Repository navigation
Bug: Build for arm64 from x86 machine #7970
Copy link
Copy link
Closed
Labels
Description
Description:
As the title suggests, I'm trying to build AWS Lambda images for AWS Graviton 2, which uses an ARM64 architecture, from my x86 machine, but I've been unsuccessful so far. Every time I try sam build, I encounter the following message:
image with reference sha256:9772b24dae18e816e254ba3dedb8d3c35370c1a5b26f0a4fe5e5d1fbf998953f was found but its platform (linux/amd64) does not match the specified platform (linux/arm64)
Im building using Go and DockerImages and following this guide I found. I encountered a similar problem in the past, when using plain docker, and as this Stackoverflow thread suggests, multiplatform/builds may be the solution but I haven't find such feature on AWS SAM documentation. Correct me if I'm mistaken.
Steps to reproduce:
This are my build files so far :
Dockerimage
FROM public.ecr.aws/docker/library/golang:1.21 as build-image
ARG ENTRY_POINT
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN GOARCH=arm64 GOOS=linux go build -tags lambda.norpc -o lambda-handler ${ENTRY_POINT}
FROM public.ecr.aws/lambda/provided:al2023
COPY --from=build-image /src/lambda-handler .
ENTRYPOINT ./lambda-handler
Lambdas general configuration*
Function:
Timeout: 10
MemorySize: 384
Environment:
Variables:
ASSETS_FOLDER: !Ref AssetsFolder
DB_URI: !Ref MongoURI
DB_NAME: !Ref DBName
RUNNING_MODE: !Ref RunningMode
LOGGING_LEVEL: !Ref LambdaLoggingLevel
LOGGING_PRETTY: !Ref LambdaPrettyLogs
Architectures:
- !Ref LambdaArchitecture
Tags:
Project: Bitacora
LoggingConfig:
LogFormat: JSON
LogGroup: !Ref LambdasLogGroup
ApplicationLogLevel: DEBUG
Tracing: Active
Specific function configuration*
CheckHealthFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
Events:
CatchAll:
Type: Api
Properties:
Path: /health
Method: GET
RestApiId: !Ref BitacoraAPI
Observed result:
Error: failed to get destination image "sha256:33125dcab31437e4a17aba5109c3bc9780410874b58075d477fd23104bd947ea": image with reference sha256:33125dcab31437e4a17aba5109c3bc9780410874b58075d477fd23104bd947ea was found but its platform (linux/amd64) does not match the specified platform (linux/arm64)
Expected result:
Building without problems for arm64 architectures
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Manjaro Linux
sam --version: SAM CLI, version 1.132.0- AWS region: us-east-1
{
"version": "1.132.0",
"system": {
"python": "3.12.8",
"os": "Linux-6.12.20-2-MANJARO-x86_64-with-glibc2.40"
},
"additional_dependencies": {
"docker_engine": "28.0.4",
"aws_cdk": "Not available",
"terraform": "Not available"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}
Add --debug flag to command you are running
Reacted by jjjsmz
Activity
valerena commentedon May 27, 2025
Actually the functions of type
Imageare built directly by SAM CLI usingdockerand they don't useaws-lambda-builders. So in this case, the problem might be that the build process is being triggered mentioning the other architecture, but not completely enforcing it.There are two things onto this:
arm64Docker image. On the SAM CLI docs, this is is mentioned on the page that mentions how to install Docker ("Linux" section) and it's:sam buildis not passing the platform correctly todocker build, even though it is supposed to be passed as part of the code. We might have to investigate more why this error is being thrown. If you run the previous command, maybe you can try to be explicit on asking for the arm64 version of the images if possible (likeFROM public.ecr.aws/lambda/provided:al2023-arm64).Another alternative is to build your function just using Docker
docker build --platform 'linux/arm64' -t hello-world-sam:latest, and update your template to point to that already built image instead of building it with SAM CLI:aidanscode commentedon Jul 10, 2025
I'm not the original creator of this issue but I'm running into basically the error and hoping to keep this issue moving. The main difference is that I'm on an ARM based computer (Mac M4) and trying to build an x86-based image instead of the opposite (x86 building an ARM image).
I've also confirmed Rosetta 2 is installed and working
Here's my template definition:
If I try to run the docker build directly, it succeeds:
docker buildx build --platform linux/amd64 --load -t client-portal-doc-to-pdf .Yet running through
sam buildfails with error (full debug log is later in this comment)Regarding the above suggestions from @valerena ,
This is failing on my machine:
Though I'm seeing online that this shouldn't be needed on Mac running Docker Desktop anyway?
And the other suggestion
I'm not sure exactly how the template should look after adding this field, but only adding the
ImageUrifield under Properties and setting toclient-portal-doc-to-pdf:latest(which I successfully built using the command above) then runningsam buildgives the same errorIf I add ImageUri to Properties, remove DockerContext and Dockerfile from Metadata, and then run
sam build, it "succeeds" but doesn't seem to have actually built anything, and attempting to run the Lambda after usingsam local invoke "DOCToPDFFunction"gives meNot sure why it's not finding the local image since I can see it in my Docker Desktop
Here's the full debug log of me running
sam buildoff of my original lambda template (The one fully included earlier in this comment)Hope this helps, happy to provide more information as needed
sudara999 commentedon Jan 20, 2026
Can confirm that running the first command @valerena mentioned allowed me to run my arm64 lambda on my amd64 (debian 12) device. Thanks!
docker run --rm --privileged multiarch/qemu-user-static --reset -p yesreedham-aws commentedon Oct 12, 2026
Like I mentioned in #7598, this is also probably fixed by using
--use-buildkitwithsam build.bnusunny commentedon Nov 13, 2026
To build arm64 images on an x86 host, Docker needs QEMU emulation registered (
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes), andsam build --use-buildkitalso handles the cross-platform build. Another user confirmed this works, so we'll close this in favour of #7598. Please reopen if it still fails with both in place.github-actions commentedon Nov 13, 2026
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.