Skip to main content

The CDK Construct Library for AWS Lambda in Python

Project description

Amazon Lambda Python Library

---

cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


This library provides constructs for Python Lambda functions.

To use this module, you will need to have Docker installed.

Python Function

Define a PythonFunction:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_lambda as lambda_
from aws_cdk.aws_lambda_python import PythonFunction

PythonFunction(self, "MyFunction",
    entry="/path/to/my/function", # required
    index="my_index.py", # optional, defaults to 'index.py'
    handler="my_exported_func", # optional, defaults to 'handler'
    runtime=lambda_.Runtime.PYTHON_3_6
)

All other properties of lambda.Function are supported, see also the AWS Lambda construct library.

Module Dependencies

If requirements.txt or Pipfile exists at the entry path, the construct will handle installing all required modules in a Lambda compatible Docker container according to the runtime.

Python bundles are only recreated and published when a file in a source directory has changed. Therefore (and as a general best-practice), it is highly recommended to commit a lockfile with a list of all transitive dependencies and their exact versions. This will ensure that when any dependency version is updated, the bundle asset is recreated and uploaded.

To that end, we recommend using pipenv or poetry which has lockfile support.

Lambda with a requirements.txt

.
├── lambda_function.py # exports a function named 'handler'
├── requirements.txt # has to be present at the entry path

Lambda with a Pipfile

.
├── lambda_function.py # exports a function named 'handler'
├── Pipfile # has to be present at the entry path
├── Pipfile.lock # your lock file

Lambda with a poetry.lock

.
├── lambda_function.py # exports a function named 'handler'
├── pyproject.toml # has to be present at the entry path
├── poetry.lock # your poetry lock file

Lambda Layer Support

You may create a python-based lambda layer with PythonLayerVersion. If PythonLayerVersion detects a requirements.txt or Pipfile or poetry.lock with the associated pyproject.toml at the entry path, then PythonLayerVersion will include the dependencies inline with your code in the layer.

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
lambda_.PythonFunction(self, "MyFunction",
    entry="/path/to/my/function",
    layers=[
        lambda_.PythonLayerVersion(self, "MyLayer",
            entry="/path/to/my/layer"
        )
    ]
)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk.aws-lambda-python-1.112.0.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_cdk.aws_lambda_python-1.112.0-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file aws-cdk.aws-lambda-python-1.112.0.tar.gz.

File metadata

  • Download URL: aws-cdk.aws-lambda-python-1.112.0.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.5

File hashes

Hashes for aws-cdk.aws-lambda-python-1.112.0.tar.gz
Algorithm Hash digest
SHA256 84255157e1d3fbc7677a653c5abfb0cc62fa0e25fd621848314cabd0d2766133
MD5 116d960c8d5c3f54b572ebb6c3897c4c
BLAKE2b-256 2770873cea1839d5b6cab44c847adb5b6c1c93806a2dd2f0f8bf1c1372e2c5da

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_lambda_python-1.112.0-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.aws_lambda_python-1.112.0-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.5

File hashes

Hashes for aws_cdk.aws_lambda_python-1.112.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d48d8e7e8572568d48967a49a1c4e01271e5f99825eba5b3a2ee632292cc93c4
MD5 0cdca3c5d79b52fb974811fa7027d7b1
BLAKE2b-256 b34e25590c563333862d2b3cde690c8a2a3fd408508c4772dfb3e5a2d734a9d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page