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

Argument data models.

pydantic model runway.cfngin.hooks.awslambda.models.args.AwsLambdaHookArgs[source]

Bases: HookArgsBaseModel

Base class for AWS Lambda hook arguments.

Show JSON schema
{
   "title": "AwsLambdaHookArgs",
   "description": "Base class for AWS Lambda hook arguments.",
   "type": "object",
   "properties": {
      "tags": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Tags",
         "type": "object"
      },
      "bucket_name": {
         "title": "Bucket Name",
         "type": "string"
      },
      "cache_dir": {
         "anyOf": [
            {
               "format": "path",
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Cache Dir"
      },
      "compatible_architectures": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Compatible Architectures"
      },
      "compatible_runtimes": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Compatible Runtimes"
      },
      "docker": {
         "$ref": "#/$defs/DockerOptions",
         "default": {
            "disabled": false,
            "extra_files": [],
            "file": null,
            "image": null,
            "name": null,
            "pull": true
         }
      },
      "extend_gitignore": {
         "default": [],
         "items": {
            "type": "string"
         },
         "title": "Extend Gitignore",
         "type": "array"
      },
      "license": {
         "anyOf": [
            {
               "maxLength": 256,
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "License"
      },
      "object_prefix": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Object Prefix"
      },
      "runtime": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Runtime"
      },
      "slim": {
         "default": true,
         "title": "Slim",
         "type": "boolean"
      },
      "source_code": {
         "format": "directory-path",
         "title": "Source Code",
         "type": "string"
      },
      "use_cache": {
         "default": true,
         "title": "Use Cache",
         "type": "boolean"
      }
   },
   "$defs": {
      "DockerOptions": {
         "description": "Docker options.",
         "properties": {
            "disabled": {
               "default": false,
               "title": "Disabled",
               "type": "boolean"
            },
            "extra_files": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Extra Files",
               "type": "array"
            },
            "file": {
               "anyOf": [
                  {
                     "format": "file-path",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "File"
            },
            "image": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Image"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Name"
            },
            "pull": {
               "default": true,
               "title": "Pull",
               "type": "boolean"
            }
         },
         "title": "DockerOptions",
         "type": "object"
      }
   },
   "required": [
      "bucket_name",
      "source_code"
   ]
}

field bucket_name: str = PydanticUndefined

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.

field cache_dir: Path | None = None

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

field compatible_architectures: list[str] | None = None

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
field compatible_runtimes: list[str] | None = None

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
field docker: DockerOptions = DockerOptions(disabled=False, extra_files=[], file=None, image=None, name=None, pull=True)

Docker options.

field 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
field license: Annotated[str | None, Field(max_length=256)] = None

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
Constraints:
  • max_length = 256

field object_prefix: str | None = None

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>).

field runtime: Annotated[str | None, Field(validate_default=True)] = None

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.

field slim: bool = True

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.

field source_code: DirectoryPath = PydanticUndefined

Path to the Lambda Function source code.

Example

args:
  source_code: ./my/package
Constraints:
  • path_type = dir

field use_cache: bool = True

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

pydantic model runway.cfngin.hooks.awslambda.models.args.DockerOptions[source]

Bases: BaseModel

Docker options.

Show JSON schema
{
   "title": "DockerOptions",
   "description": "Docker options.",
   "type": "object",
   "properties": {
      "disabled": {
         "default": false,
         "title": "Disabled",
         "type": "boolean"
      },
      "extra_files": {
         "default": [],
         "items": {
            "type": "string"
         },
         "title": "Extra Files",
         "type": "array"
      },
      "file": {
         "anyOf": [
            {
               "format": "file-path",
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "File"
      },
      "image": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Image"
      },
      "name": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Name"
      },
      "pull": {
         "default": true,
         "title": "Pull",
         "type": "boolean"
      }
   }
}

field disabled: bool = False

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
field 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
field file: FilePath | None = None

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
field image: str | None = None

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
field name: str | None = None

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
field pull: bool = True

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
pydantic model runway.cfngin.hooks.awslambda.models.args.PythonHookArgs[source]

Bases: AwsLambdaHookArgs

Hook arguments for a Python AWS Lambda deployment package.

Show JSON schema
{
   "title": "PythonHookArgs",
   "description": "Hook arguments for a Python AWS Lambda deployment package.",
   "type": "object",
   "properties": {
      "tags": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Tags",
         "type": "object"
      },
      "bucket_name": {
         "title": "Bucket Name",
         "type": "string"
      },
      "cache_dir": {
         "anyOf": [
            {
               "format": "path",
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Cache Dir"
      },
      "compatible_architectures": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Compatible Architectures"
      },
      "compatible_runtimes": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Compatible Runtimes"
      },
      "docker": {
         "$ref": "#/$defs/DockerOptions",
         "default": {
            "disabled": false,
            "extra_files": [],
            "file": null,
            "image": null,
            "name": null,
            "pull": true
         }
      },
      "extend_gitignore": {
         "default": [],
         "items": {
            "type": "string"
         },
         "title": "Extend Gitignore",
         "type": "array"
      },
      "license": {
         "anyOf": [
            {
               "maxLength": 256,
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "License"
      },
      "object_prefix": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Object Prefix"
      },
      "runtime": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Runtime"
      },
      "slim": {
         "default": true,
         "title": "Slim",
         "type": "boolean"
      },
      "source_code": {
         "format": "directory-path",
         "title": "Source Code",
         "type": "string"
      },
      "use_cache": {
         "default": true,
         "title": "Use Cache",
         "type": "boolean"
      },
      "extend_pip_args": {
         "anyOf": [
            {
               "items": {
                  "type": "string"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Extend Pip Args"
      },
      "strip": {
         "default": true,
         "title": "Strip",
         "type": "boolean"
      },
      "use_pipenv": {
         "default": true,
         "title": "Use Pipenv",
         "type": "boolean"
      },
      "use_poetry": {
         "default": true,
         "title": "Use Poetry",
         "type": "boolean"
      }
   },
   "$defs": {
      "DockerOptions": {
         "description": "Docker options.",
         "properties": {
            "disabled": {
               "default": false,
               "title": "Disabled",
               "type": "boolean"
            },
            "extra_files": {
               "default": [],
               "items": {
                  "type": "string"
               },
               "title": "Extra Files",
               "type": "array"
            },
            "file": {
               "anyOf": [
                  {
                     "format": "file-path",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "File"
            },
            "image": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Image"
            },
            "name": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Name"
            },
            "pull": {
               "default": true,
               "title": "Pull",
               "type": "boolean"
            }
         },
         "title": "DockerOptions",
         "type": "object"
      }
   },
   "required": [
      "bucket_name",
      "source_code"
   ]
}

field extend_pip_args: list[str] | None = None

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. --requirement, --target, --no-input). Providing duplicate arguments will result in an error.

Example

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

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__*

field strip: bool = True

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.

field use_pipenv: bool = True

Whether pipenv should be used if determined appropriate.

field use_poetry: bool = True

Whether poetry should be used if determined appropriate.