Bug: Build for arm64 from x86 machine
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
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](https://aws.amazon.com/blogs/compute/introducing-the-amazon-linux-2023-runtime-for-aws-lambda/). I encountered a similar problem in the past, when using plain docker, and as [this Stackoverflow thread suggests](https://stackoverflow.com/questions/69056799/is-it-possible-to-build-an-arm64-image-from-an-existing-x86-64-image), 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)
1. OS: Manjaro Linux
2. `sam --version`: SAM CLI, version 1.132.0
3. 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`
Contributor guide
Assessment
This issue has not been assessed yet.