Skip to content

Latest commit

 

History

History
208 lines (156 loc) · 6.44 KB

awslambda.PythonLayer.rst

File metadata and controls

208 lines (156 loc) · 6.44 KB

awslambda.PythonLayer

Hook Path

runway.cfngin.hooks.awslambda.PythonLayer

This hook creates deployment packages for Python Lambda Layers, uploads them to S3, and returns data about the deployment package.

The return value can be retrieved using the hook_data lookup or by interacting with the ~runway.context.CfnginContext object passed to the .

To use this hook to install dependencies, it must be able to find project metadata files. This can include Pipefile & Pipfile.lock files (pipenv), a pyproject.toml & poetry.lock files (poetry), or a requirements.txt file (pip). The project metadata files can exist either in the source code directory (value of source_code arg) or in the same directory as the CFNgin configuration file. If metadata files are not found, dependencies will not be included in the deployment package.

This hook will always use Docker to install/compile dependencies unless explicitly configured not to. It is recommended to always use Docker to ensure a clean and consistent build. It also ensures that binary files built during the install process are compatible with AWS Lambda.

2.5.0

Table of Contents

Args

Arguments that can be passed to the hook in the ~cfngin.hook.args field.

Documentation for each field is automatically generated from class attributes in the source code. When specifying the field, exclude the class name.

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.bucket_name

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.cache_dir

If not provided, the cache directory is .runway/awslambda/pip_cache within the current working directory.

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.compatible_architectures

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.compatible_runtimes

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.docker

runway.cfngin.hooks.awslambda.models.args.DockerOptions.disabled

runway.cfngin.hooks.awslambda.models.args.DockerOptions.extra_files

runway.cfngin.hooks.awslambda.models.args.DockerOptions.file

runway.cfngin.hooks.awslambda.models.args.DockerOptions.image

runway.cfngin.hooks.awslambda.models.args.DockerOptions.name

runway.cfngin.hooks.awslambda.models.args.DockerOptions.pull

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.extend_gitignore

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.extend_pip_args

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.license

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.object_prefix

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.runtime

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.slim

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.source_code

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.strip

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.use_cache

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.use_pipenv

runway.cfngin.hooks.awslambda.models.args.PythonHookArgs.use_poetry

Return Value

runway.cfngin.hooks.awslambda.models.responses.AwsLambdaHookDeployResponse

Example

FROM public.ecr.aws/sam/build-python3.9:latest

RUN yum install libxml2-devel xmlsec1-devel xmlsec1-openssl-devel libtool-ltdl-devel -y
namespace: ${namespace}
cfngin_bucket: ${cfngin_bucket}
src_path: ./

pre_deploy:
  - path: runway.cfngin.hooks.awslambda.PythonLayer
    data_key: awslambda.example-function-no-docker
    args:
      bucket_name: ${bucket_name}
      compatible_runtimes:
        - python3.9
        - python3.10
      docker:
        disabled: true
      extend_gitignore:
        - "*.lock"
        - '*.md'
        - '*.toml'
        - tests/
      extend_pip_args:
        - '--proxy'
        - '[user:passwd@]proxy.server:port'
      runtime: python3.9
      slim: false
      source_code: ./src/example-function
  - path: runway.cfngin.hooks.awslambda.PythonLayer
    data_key: awslambda.example-function
    args:
      bucket_name: ${bucket_name}
      # docker:  # example of default & inferred values
      #   disabled: false  # default value
      #   image: public.ecr.aws/sam/build-python3.9:latest  # inferred from runtime
      #   pull: true  # default value
      extend_gitignore:
        - "*.lock"
        - '*.md'
        - '*.toml'
        - tests/
      extend_pip_args:
        - '--proxy'
        - '[user:passwd@]proxy.server:port'
      runtime: python3.9
      source_code: ./src/example-function
  - path: runway.cfngin.hooks.awslambda.PythonLayer
    data_key: awslambda.xmlsec
    args:
      bucket_name: ${bucket_name}
      docker:
        extra_files:
          - /usr/lib64/libltdl.so.*
          - /usr/lib64/libxml2.so.*
          - /usr/lib64/libxmlsec1-openssl.so
          - /usr/lib64/libxmlsec1.so.*
          - /usr/lib64/libxslt.so.*
        file: ./Dockerfile
        pull: false
      extend_gitignore:
        - "*.lock"
        - '*.md'
        - '*.toml'
        - tests/
      source_code: ./src/xmlsec-function
      strip: false

stacks:
  - name: example-stack
    class_path: blueprints.ExampleBlueprint
    parameters:
      XmlCompatibleRuntimes: ${awslambda.CompatibleRuntimes awslambda.xmlsec}
      XmlS3Bucket: ${awslambda.S3Bucket awslambda.xmlsec}
      XmlS3Key: ${awslambda.S3Key awslambda.xmlsec}
  ...