amazon/aws-lambda-python
AWS Lambda base images for Python
1M+
AWS provided base images for Lambda contain all the required components to run your functions packaged as container images on AWS Lambda. These base images contain the Amazon Linux Base operating system, the runtime for a given language, dependencies and the Lambda Runtime Interface Client (RIC), which implements the Lambda Runtime API. The Lambda Runtime Interface Client allows your runtime to receive requests from and send requests to the Lambda service.
To learn more about the composition of the base images you can visit https://github.com/aws/aws-lambda-base-images.
AWS will regularly provide security patches and other updates for these base images. These images are similar to the AWS Lambda execution environment on the cloud to allow customers to easily packaging functions to the container image. However, we may choose to optimize the container images by changing the components or dependencies included. When deployed to AWS Lambda these images will be run as-is.
You can get started by using these images in your Dockerfile and coping your function code into the /var/task
folder in your image.
Example Dockerfile
below:
FROM public.ecr.aws/lambda/python:3.8
# Copy function code
COPY app.py ${LAMBDA_TASK_ROOT}
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.handler" ]
You can then locally test your function using the docker build and docker run commands.
To build you image:
docker build -t <image name> .
To run your image locally:
docker run -p 9000:8080 <image name>
In a separate terminal, you can then locally invoke the function using cURL:
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'
To learn more on deploying the function to ECR, check out the AWS documentation on Creating a repository and Pushing an image
docker pull amazon/aws-lambda-python