- Newest
- Most votes
- Most comments
When building Docker images for Lambda functions, especially on newer architectures like M2 Macbooks, you need to ensure compatibility with Lambda's container image requirements.
The issue you're experiencing is because Lambda doesn't support multi-architecture container images. Even though Lambda provides multi-architecture base images, the image you build must target only one specific architecture.
Instead of using the legacy builder with DOCKER_BUILDKIT=0, you should use the following approach:
docker buildx build --platform linux/amd64 --provenance=false -t myproject .
The key components here are:
--platform linux/amd64- Specifies the target architecture (use x86_64 for Lambda)--provenance=false- This is critical as Lambda doesn't support the default provenance metadata
If you're targeting ARM-based Lambda functions, you would use:
docker buildx build --platform linux/arm64 --provenance=false -t myproject .
After building the image, you can tag and push it to ECR as usual:
docker tag myproject:latest <your-account-id>.dkr.ecr.<region>.amazonaws.com/myproject:latest
docker push <your-account-id>.dkr.ecr.<region>.amazonaws.com/myproject:latest
This approach uses the modern Docker buildx plugin while ensuring compatibility with Lambda's container image requirements.
Sources
How to build container images on M2 Macbook and use them in Lambda functions | AWS re:Post
Deploy Python Lambda functions with container images - AWS Lambda
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
