Skip to content

AWS Lambda Function w/ ECR Docker Container does not work when Docker Image made on Apple Silicon M2 Macbook

0

Hello,

I was going through this AWS Tutorial from Free Code Camp — The Serverless Architecture Handbook: How to Publish a Node Js Docker Image to AWS ECR and Deploy the Container to AWS Lambda.

I was doing this on my main coding machine, a 2022 MacBook Air w/ an Apple Silicon M2 chip, 24 GB of RAM, and MacOS Sequoia 15.5.

Everything was going fine, I was able to push the Docker Image that was built on my MacBook Air to AWS ECR just fine, until I got to the part in the tutorial where you create the Serverless Lambda function and attach the Container from AWS ECR to it. I tried creating a new Lambda functions, chose "Container Image" for the Lambda function, gave it a name and selected the ECR Docker Image I had uploaded, and chose arm64 for the Architecture, as that is what the Apple Silicon M2 chip is. At that point, I got the following error when I tried to save the AWS Lambda function —

The image manifest, config or layer media type for the source image 415740581749.dkr.ecr.us-west-2.amazonaws.com/aws-ecs-lambda-practice@sha256:c9ab45436ca59991f2c108af7a891167a48287883c988b94a7e54412d3c0a10d is not supported.

Enter image description here

I tried re-doing the Docker Image and re-uploading it to AWS ECR and then tried attaching it again with AWS Lambda function, several times, trying both arm64 and x86_64 for Architecture, but no matter what I tried, I kept getting the same exact error, over and over again. I even tried building the Docker Image on my MacBook Air with the Apple Silicon M2 chip with the switches --platform arm64 or --platorm amd64, but still go the same error when I tried attaching it to the AWS Lambda function.

I was finally able to get through the Free Code Camp tutorial by contacting the author, who was kind enough to work with me on this, though we're eight hours in time zones apart across the world, and he was able to upload a Docker Iimage created on Windows (his chosen platform) to my AWS ECR, and that worked well with the AWS Lambda function and I was able to create the function with no such error and get to the end of the tutorial successfully seeing the Node.JS app working via AWS Lambda & the Container. But... this means each every time I would have to build the Docker Image in VM software like Parallels, VM Ware Fusion, or Vistual Box for MacOS, using Ubuntu Linux, Alpine Linux or Windows and then upload that to AWS ECR; or, find a friend using those OS platforms already on their computer with Docker and have them build the image for me. This seems like way too many convoluted steps to upload a Docker Image to AWS ECR and use it with an AWS Lambda function from a Apple Silicon M* Series chip Macintosh.

Has anyone else using Apple Macs with the Apple Silicon M* series of chips seen this when trying to build & attach Docker Containers to AWS Lambda functions? At this point, I can only think it is the Apple Silicon M2 chip on which the Docker Image is built that is the problem that AWS Lambda keep erroring on and rejecting. I really have a problem believing AWS has not come up with a solution yet for Apple Macintosh users with the Apple Silicon M* Series chips to use such Docker Images pushed up to AWS ECR and used with AWS Lambda functions.

Does anyone know of a solution for this, other than the kludgy running a VM and building the Docker Image in that, or having a friend with Linux or Windows build the Docker Image for me? Any help, please, would be most appreciated. Thank you in advance.

2 Answers
0
Accepted Answer

Hello.

As stated in the automated response from re:Post Agent, it is possible to avoid the error by implementing CI/CD or using EC2.
Also, if the container image is not too large, it can be built using CloudShell.
I think that with CloudShell you can build container images without being affected by the CPU architecture.
However, if your container image is large, it may be better to build it using EC2 or similar.
https://docs.aws.amazon.com/cloudshell/latest/userguide/tutorial-docker-cli.html

By the way, have you tried the "--provenance=false" option as mentioned in the Stackoverflow answer?
https://stackoverflow.com/questions/65608802/cant-deploy-container-image-to-lambda-function

docker build --provenance=false -t batch-demo-lambda .
EXPERT
answered a year ago
  • That did it! A combination of using the flags for the build, --platform linux/amd64 --provenance=false in the Docker build command built the Docker Image correctly, it uploaded a-okay to my AWS ECR, and... I attached it to the AWS Lambda function successfully! Huzzah! Yay! 5 ⭐️'s. Perfect! No notes. My littel test Node.JS app is now running a-okay there (though I'll be taking it down soon as not to be charged much more, this was just a test for the tutorial. Thank you aos much @Riku Kobayashi. You were most helpful. And thank you for the links to the AWS Guide to building the Docker Image and the Stackoverflow article on using the --provenance=false. I've bookmarked both of them. One question — is there an article here on AWS re:Post somewhere about using these Docker build switches or CloudShell or Cloud9 or an EC2 w/ Docker to build Docker Images when you're building on an Apple Macintosh with the Apple Silicon M* Series chips? That would have been especially helpful in this case, but I couldn't find anything before finding my article. I tried searching here in AWS re:Post with "AWS ECR Docker Container Build AWS Lambda Apple Silicon," and it returned pages and pages of stuff that had nothing to do with Macs with Apple Silicon chips, whatsoever. Had my eyes spinning. 😵‍💫 But thank you, so much, for the help, again.

  • I'm glad your problem seems to have been resolved.

    That would have been especially helpful in this case, but I couldn't find anything before finding my article. I tried searching here in AWS re:Post with "AWS ECR Docker Container Build AWS Lambda Apple Silicon," and it returned pages and pages of stuff that had nothing to do with Macs with Apple Silicon chips, whatsoever. Had my eyes spinning.

    I also searched for it, but I couldn't find any such article in AWS re:Post.

  • Hooray!! Thank you so much for the article! 👏 👏 👏

0

The issue you're experiencing is indeed related to building Docker images on Apple Silicon (M1/M2) Macs for use with AWS Lambda. This is a known compatibility problem that many developers have encountered.

When you build a Docker image on an M1/M2 Mac, it creates an ARM64 architecture image by default. However, AWS Lambda typically expects x86_64 architecture images, which is why you're encountering the error when trying to use your locally built image.

There are a few ways to address this issue:

  1. Use Docker's buildx feature to create multi-architecture images: Instead of building your image normally, you can use Docker's buildx command to create an image that works on both ARM and x86 architectures. Here's an example command:

    docker buildx build --platform linux/amd64 -t your-image-name .
    

    This will create an x86_64 compatible image even when building on an M1/M2 Mac.

  2. Specify the platform when building: You can explicitly specify the platform when building your Docker image:

    docker build --platform linux/amd64 -t your-image-name .
    
  3. Use a CI/CD pipeline: If you're working on a team or need a more robust solution, consider setting up a CI/CD pipeline (e.g., GitHub Actions, GitLab CI, or AWS CodeBuild) to build your Docker images on x86_64 machines.

  4. Use AWS Cloud9 or EC2: You could use an AWS Cloud9 environment or launch an EC2 instance to build your Docker images in an x86_64 environment.

After building the image using one of these methods, push it to ECR, and it should work correctly with Lambda.

Remember to ensure that your Dockerfile is set up correctly for Lambda, including using a compatible base image and setting up the necessary runtime interface clients.

By using one of these approaches, you should be able to create Docker images on your M1/M2 Mac that are compatible with AWS Lambda, without needing to use a VM or rely on a friend with a different system.
Sources
Getting a "SINGLE_BUILD_CONTAINER_DEAD" error with a custom Docker image | AWS re:Post
Lambda with Docker (from ECR) is Failing to Install All Depedencies | AWS re:Post

answered a year ago
EXPERT
reviewed a year ago
  • I followed all the steps this LLM Amazon Q response offered above through Step 2 — it still did not work when trying to attach the uploaded container to the AWS Lambda function. I guess I will have to try a CI/CD pipeline, like AWS CodeBuild, or try building the Docker Image on an AWS EC2 or Cloud9. Oh well...

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.