You can add an extension to your function as a Lambda layer. Using layers enables you to share extensions across your organization or to the entire community of Lambda developers. You can add one or more extensions to a layer. You can register up to 10 extensions for a function.
You add the extension to your function using the same method as you would for any layer. For more information, see Using layers with your Lambda function.
Add an extension to your function (console)
-
Open the Functions page of the Lambda console.
-
Choose a function.
-
Choose the Code tab if it is not already selected.
-
Under Layers, choose Edit.
-
For Choose a layer, choose Specify an ARN.
-
For Specify an ARN, enter the Amazon Resource Name (ARN) of an extension layer.
-
Choose Add.
You can add extensions to your container image. The ENTRYPOINT container image setting specifies the main process for the function. Configure the ENTRYPOINT setting in the Dockerfile, or as an override in the function configuration.
You can run multiple processes within a container. Lambda manages the lifecycle of the main process and any additional processes. Lambda uses the Extensions API to manage the extension lifecycle.
An external extension runs in a separate process from the Lambda function. Lambda starts a process for each extension in the /opt/extensions/
directory. Lambda uses the Extensions API to manage the extension lifecycle. After the function has run to completion, Lambda sends a Shutdown
event to each external extension.
Example of adding an external extension to a Python base image
FROM public.ecr.aws/lambda/python:3.8
# Copy and install the app
COPY /app /app
WORKDIR /app
RUN pip install -r requirements.txt
# Add an extension from the local directory into /opt
ADD my-extension.zip /opt
CMD python ./my-function.py
To learn more about extensions, we recommend the following resources:
- For a basic working example, see Building Extensions for AWS Lambda on the AWS Compute Blog.
- For information about extensions that AWS Lambda Partners provides, see Introducing AWS Lambda Extensions on the AWS Compute Blog.
- To view available example extensions and wrapper scripts, see AWS Lambda Extensions on the AWS Samples GitHub repository.