runway.cfngin.hooks.awslambda.models.args module

Argument data models.

class runway.cfngin.hooks.awslambda.models.args.DockerOptions[source]

Bases: runway.utils.BaseModel

Docker options.

disabled: bool

Explicitly disable the use of docker (default False).

If not disabled and Docker is unreachable, the hook will result in an error.

Example

args:
  docker:
    disabled: true
extra_files: List[str]

List of absolute file paths within the Docker container to copy into the deployment package.

Some Python packages require extra OS libraries (*.so) files at runtime. These files need to be included in the deployment package for the Lambda Function to run. List the files here and the hook will handle copying them into the deployment package.

The file name may end in a wildcard (*) to accommodate .so files that end in an variable number (see example below).

If the file does not exist, it will result in an error.

Example

args:
  docker:
    extra_files:
      - /usr/lib64/mysql/libmysqlclient.so.*
      - /usr/lib64/libxmlsec1-openssl.so
file: Optional[FilePath]

Dockerfile to use to build an image for use in this process.

This, image , or runtime must be provided. If not provided, image will be used.

Example

args:
  docker:
    file: Dockerfile
image: Optional[str]

Docker image to use. If the image does not exist locally, it will be pulled.

This, file (takes precedence), or runtime must be provided. If only runtime is provided, it will be used to determine the appropriate image to use.

Example

args:
  docker:
    image: public.ecr.aws/sam/build-python3.9:latest
name: Optional[str]

When providing a Dockerfile, this will be the name applied to the resulting image. It is the equivalent to name in the name:tag syntax of the docker build [--tag, -t] command option.

If not provided, a default image name is used.

This field is ignore unless file is provided.

Example

args:
  docker:
    file: Dockerfile
    name: ${namespace}.runway.awslambda
pull: bool

Always download updates to the specified image before use. When building an image, the FROM image will be updated during the build process (default True).

Example

args:
  docker:
    pull: false
class Config[source]

Bases: object

Model configuration.

__init__()
__new__(**kwargs)
__contains__(name: object) bool

Implement evaluation of ‘in’ conditional.

Parameters

name – The name to check for existence in the model.

__getitem__(name: str) Any

Implement evaluation of self[name].

Parameters

name – Attribute name to return the value for.

Returns

The value associated with the provided name/attribute name.

Raises

AttributeError – If attribute does not exist on this object.

__init__(**data: Any) None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

__iter__() TupleGenerator

so dict(model) works

__new__(**kwargs)
__pretty__(fmt: Callable[[Any], Any], **kwargs: Any) Generator[Any, None, None]

Used by devtools (https://python-devtools.helpmanual.io/) to provide a human readable representations of objects

__repr_name__() str

Name of the instance’s class, used in __repr__.

__rich_repr__() RichReprResult

Get fields for Rich library

__setitem__(name: str, value: Any) None

Implement item assignment (e.g. self[name] = value).

Parameters
  • name – Attribute name to set.

  • value – Value to assign to the attribute.

classmethod __try_update_forward_refs__(**localns: Any) None

Same as update_forward_refs but will not raise exception when forward references are not defined.

classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns

new model instance

dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

get(name: str, default: Any = None) Any

Safely get the value of an attribute.

Parameters
  • name – Attribute name to return the value for.

  • default – Value to return if attribute is not found.

json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) str

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

class runway.cfngin.hooks.awslambda.models.args.AwsLambdaHookArgs[source]

Bases: runway.cfngin.hooks.base.HookArgsBaseModel

Base class for AWS Lambda hook arguments.

bucket_name: str

Name of the S3 Bucket where deployment package is/will be stored. The Bucket must be in the same region the Lambda Function is being deployed in.

cache_dir: Optional[Path]

Explicitly define the directory location. Must be an absolute path or it will be relative to the CFNgin module directory.

compatible_architectures: Optional[List[str]]

A list of compatible instruction set architectures. (https://docs.aws.amazon.com/lambda/latest/dg/foundation-arch.html)

Only used by Lambda Layers.

Example

args:
  compatible_architectures:
    - x86_64
    - arm64
compatible_runtimes: Optional[List[str]]

A list of compatible function runtimes. When provided, the runtime being used to build the deployment package must be included in the list or an error will be raised.

Only used by Lambda Layers.

Example

args:
  compatible_runtimes:
    - python3.9
    - python3.10
docker: DockerOptions

Docker options.

extend_gitignore: List[str]

gitignore rules that should be added to the rules already defined in a .gitignore file in the source code directory. This can be used with or without an existing file. Files that match a gitignore rule will not be included in the deployment package.

.git/ & .gitignore will always be added.

Important

This only applies to files in the source_code directory.

Example

args:
  extend_gitignore:
    - cfngin.yml
    - poetry.lock
    - poetry.toml
    - pyproject.toml
license: Optional[str]

The layer’s software license. Can be any of the following:

  • A SPDX license identifier (e.g. Apache-2.0).

  • The URL of a license hosted on the internet (e.g. https://opensource.org/licenses/Apache-2.0).

  • The full text of the license.

Only used by Lambda Layers.

Example

args:
  license: Apache-2.0
object_prefix: Optional[str]

Prefix to add to the S3 Object key.

The object will always be prefixed with awslambda/functions. If provided, the value will be added to the end of the static prefix (e.g. awslambda/<functions|layers>/<object_prefix>/<file name>).

__contains__(name: object) bool

Implement evaluation of ‘in’ conditional.

Parameters

name – The name to check for existence in the model.

__getitem__(name: str) Any

Implement evaluation of self[name].

Parameters

name – Attribute name to return the value for.

Returns

The value associated with the provided name/attribute name.

Raises

AttributeError – If attribute does not exist on this object.

__init__(**data: Any) None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

__iter__() TupleGenerator

so dict(model) works

__new__(**kwargs)
__pretty__(fmt: Callable[[Any], Any], **kwargs: Any) Generator[Any, None, None]

Used by devtools (https://python-devtools.helpmanual.io/) to provide a human readable representations of objects

__repr_name__() str

Name of the instance’s class, used in __repr__.

__rich_repr__() RichReprResult

Get fields for Rich library

__setitem__(name: str, value: Any) None

Implement item assignment (e.g. self[name] = value).

Parameters
  • name – Attribute name to set.

  • value – Value to assign to the attribute.

classmethod __try_update_forward_refs__(**localns: Any) None

Same as update_forward_refs but will not raise exception when forward references are not defined.

classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns

new model instance

dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

get(name: str, default: Any = None) Any

Safely get the value of an attribute.

Parameters
  • name – Attribute name to return the value for.

  • default – Value to return if attribute is not found.

json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) str

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

runtime: Optional[str]

Runtime of the Lambda Function (https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).

This, docker.file, or docker.image must be provided. If docker.disabled, this field is required.

When provided, the runtime available on the build system (Docker container or localhost) will be checked against this value. If they do not match, an error will be raised.

If the defined or detected runtime ever changes so that it no longer matches the deployment package in S3, the deployment package in S3 will be deleted and a new one will be built and uploaded.

slim: bool

Automatically remove information and caches from dependencies (default True). This is done by applying gitignore rules to the dependencies. These rules vary by language/runtime.

source_code: DirectoryPath

Path to the Lambda Function source code.

Example

args:
  source_code: ./my/package
use_cache: bool

Whether to use a cache directory with pip that will persist builds (default True).

class runway.cfngin.hooks.awslambda.models.args.PythonHookArgs[source]

Bases: runway.cfngin.hooks.awslambda.models.args.AwsLambdaHookArgs

Hook arguments for a Python AWS Lambda deployment package.

__contains__(name: object) bool

Implement evaluation of ‘in’ conditional.

Parameters

name – The name to check for existence in the model.

__getitem__(name: str) Any

Implement evaluation of self[name].

Parameters

name – Attribute name to return the value for.

Returns

The value associated with the provided name/attribute name.

Raises

AttributeError – If attribute does not exist on this object.

__init__(**data: Any) None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

__iter__() TupleGenerator

so dict(model) works

__new__(**kwargs)
__pretty__(fmt: Callable[[Any], Any], **kwargs: Any) Generator[Any, None, None]

Used by devtools (https://python-devtools.helpmanual.io/) to provide a human readable representations of objects

__repr_name__() str

Name of the instance’s class, used in __repr__.

__rich_repr__() RichReprResult

Get fields for Rich library

__setitem__(name: str, value: Any) None

Implement item assignment (e.g. self[name] = value).

Parameters
  • name – Attribute name to set.

  • value – Value to assign to the attribute.

classmethod __try_update_forward_refs__(**localns: Any) None

Same as update_forward_refs but will not raise exception when forward references are not defined.

classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns

new model instance

dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

get(name: str, default: Any = None) Any

Safely get the value of an attribute.

Parameters
  • name – Attribute name to return the value for.

  • default – Value to return if attribute is not found.

json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) str

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

bucket_name: str

Name of the S3 Bucket where deployment package is/will be stored. The Bucket must be in the same region the Lambda Function is being deployed in.

cache_dir: Optional[Path]

Explicitly define the directory location. Must be an absolute path or it will be relative to the CFNgin module directory.

compatible_architectures: Optional[List[str]]

A list of compatible instruction set architectures. (https://docs.aws.amazon.com/lambda/latest/dg/foundation-arch.html)

Only used by Lambda Layers.

Example

args:
  compatible_architectures:
    - x86_64
    - arm64
compatible_runtimes: Optional[List[str]]

A list of compatible function runtimes. When provided, the runtime being used to build the deployment package must be included in the list or an error will be raised.

Only used by Lambda Layers.

Example

args:
  compatible_runtimes:
    - python3.9
    - python3.10
docker: DockerOptions

Docker options.

extend_gitignore: List[str]

gitignore rules that should be added to the rules already defined in a .gitignore file in the source code directory. This can be used with or without an existing file. Files that match a gitignore rule will not be included in the deployment package.

.git/ & .gitignore will always be added.

Important

This only applies to files in the source_code directory.

Example

args:
  extend_gitignore:
    - cfngin.yml
    - poetry.lock
    - poetry.toml
    - pyproject.toml
license: Optional[str]

The layer’s software license. Can be any of the following:

  • A SPDX license identifier (e.g. Apache-2.0).

  • The URL of a license hosted on the internet (e.g. https://opensource.org/licenses/Apache-2.0).

  • The full text of the license.

Only used by Lambda Layers.

Example

args:
  license: Apache-2.0
object_prefix: Optional[str]

Prefix to add to the S3 Object key.

The object will always be prefixed with awslambda/functions. If provided, the value will be added to the end of the static prefix (e.g. awslambda/<functions|layers>/<object_prefix>/<file name>).

runtime: Optional[str]

Runtime of the Lambda Function (https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).

This, docker.file, or docker.image must be provided. If docker.disabled, this field is required.

When provided, the runtime available on the build system (Docker container or localhost) will be checked against this value. If they do not match, an error will be raised.

If the defined or detected runtime ever changes so that it no longer matches the deployment package in S3, the deployment package in S3 will be deleted and a new one will be built and uploaded.

source_code: DirectoryPath

Path to the Lambda Function source code.

Example

args:
  source_code: ./my/package
use_cache: bool

Whether to use a cache directory with pip that will persist builds (default True).

extend_pip_args: Optional[List[str]]

Additional arguments that should be passed to pip install.

Important

When providing this field, be careful not to duplicate any of the arguments passed by this hook (e.g. --requirements, --target, --no-input). Providing duplicate arguments will result in an error.

Example

args:
  extend_pip_args:
    - '--proxy'
    - '[user:passwd@]proxy.server:port'
slim: bool

Automatically remove information and caches from dependencies (default True). This is done by applying the following gitignore rules to the dependencies:

  • **/*.dist-info*

  • **/*.py[c|d|i|o]

  • **/*.so

  • **/__pycache__*

strip: bool

Whether or not to strip binary files from the dependencies (default True). This only takes effect if slim: true.

If false, the gitignore rule **/*.so is not used.

use_pipenv: bool

Whether pipenv should be used if determined appropriate.

use_poetry: bool

Whether poetry should be used if determined appropriate.

class Config[source]

Bases: object

Model configuration.

__init__()
__new__(**kwargs)