@Stability(value=Experimental)
See: Description
| Interface | Description |
|---|---|
| PythonFunctionProps |
(experimental) Properties for a PythonFunction.
|
| PythonLayerVersionProps |
(experimental) Properties for PythonLayerVersion.
|
| Class | Description |
|---|---|
| PythonFunction |
(experimental) A Python Lambda function.
|
| PythonFunction.Builder |
(experimental) A fluent builder for
PythonFunction. |
| PythonFunctionProps.Builder |
A builder for
PythonFunctionProps |
| PythonFunctionProps.Jsii$Proxy |
An implementation for
PythonFunctionProps |
| PythonLayerVersion |
(experimental) A lambda layer version.
|
| PythonLayerVersion.Builder |
(experimental) A fluent builder for
PythonLayerVersion. |
| PythonLayerVersionProps.Builder |
A builder for
PythonLayerVersionProps |
| PythonLayerVersionProps.Jsii$Proxy |
An implementation for
PythonLayerVersionProps |
---
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.
Define a PythonFunction:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import software.amazon.awscdk.services.lambda.*;
import software.amazon.awscdk.services.lambda.python.PythonFunction;
new PythonFunction(this, "MyFunction", new PythonFunctionProps()
.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.getPYTHON_3_6()));
All other properties of lambda.Function are supported, see also the AWS Lambda construct library.
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.
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
PythonFunction.Builder.create(this, "MyFunction")
.entry("/path/to/my/function")
.layers(asList(
PythonLayerVersion.Builder.create(this, "MyLayer")
.entry("/path/to/my/layer")
.build()))
.build();
Copyright © 2021. All rights reserved.