python:latest-dev image because it requires the package installer pip. The runtime uses the fully distroless production image to achieve the most secure app. Learn more about multi-stage-builds
What this guide demonstrates:
- Minimus Python images can run on AWS Lambda
- Amazon Linux is not required
- Non-root execution is supported
- Buildx defaults must be overridden
Prerequisites
You will need:- Access to an AWS account
- Permission to:
- Create ECR repositories
- Push images to ECR
- Create and invoke Lambda functions
- Access to create or use a role for the function
- Read CloudWatch logs
Process
Create Python app
Create a Python app app.py:
app.py
Create Dockerfile
First authenticate to the Minimus registry so the images can be pulled. Learn moreSave the following Dockerfile (
venv is short for virtual environment):Dockerfile
Create an ECR repository
Create an ECR repository. Official Guide from AWS In the AWS Console:
- Go to Elastic Container Registry (ECR)
-
Create a private repository. For this guide, we assume you named it:
minimus-lambda-example -
Note the full repository URI, for example:
123456789012.dkr.ecr.eu-north-1.amazonaws.com/minimus-lambda-example
Authenticate to your default registry
Authenticate the Docker CLI to your default registry so the docker command can push and pull images with Amazon ECR. Official Guide from AWSReplace the example URI in the above command with your own before running the command.
Build and push the image
Build the image using buildx. Buildx is an extended Docker build command that uses BuildKit under the hood. It is used for advanced builds involving multi-architecture, remote push, and more.
Create the Lambda function
In the AWS Console:
- Go to Lambda
- Click Create function
- Select container image
- Select
minimus-lambda-example:lambda-arm64 - Set Architecture to
arm64 - Create or select an execution role
- Create the function
Required Buildx flags
Lambda requires a single-architecture image manifest, not an OCI index with attestations. Docker Buildx adds provenance and SBOM attestations by default, which results in the pushed image becoming an OCI image index containing an extra attestation manifest (often shown asunknown/unknown platform). Since AWS Lambda does not support this image format, it is necessary to add the following Buildx flags:
--provenance=false--sbom=false
The image manifest, config or layer media type is not supported.