Repository navigation
Description
Description:
sam build always builds AWS::Serverless::WebFunction for x86_64. Lambda Web Functions run only on arm64 (Instruction set architecture):
Web Functions run exclusively on the Arm64 architecture, powered by AWS Graviton processors.
Build native dependencies for Linux on arm64 (aarch64).
Pure JavaScript code works either way. A dependency with native binaries doesn't: sam build --use-container uses the latest-x86_64 build image, so the artifact gets Linux x86_64 binaries, and they fail to load at runtime.
The architecture is hardcoded in WebFunction.architecture (samcli/lib/providers/provider.py):
@property
def architecture(self) -> str:
"""Web Functions always build for x86_64"""
return X86_64This came up in the review of #9340 (comment), and was kept on the basis that Web Functions only run on x86_64 (reply). The documentation above, and process.arch in a deployed Web Function (see below), say arm64.
Steps to reproduce:
sam.yml:
Transform: AWS::Serverless-2016-10-31
Resources:
WebFunction:
Type: AWS::Serverless::WebFunction
Properties:
AuthType: ApplicationManaged
CodeUri: .
Runtime: nodejs24.x
EntryPoint: src/index.ts
Outputs:
EndpointUrl:
Value: !Sub https://${WebFunctionEndpoint.DomainName}package.json:
{
"name": "trial-sam-deploy-01",
"version": "1.0.0",
"description": "",
"keywords": [],
"license": "ISC",
"author": "",
"type": "module",
"main": "index.js",
"dependencies": {
"@hono/node-server": "^2.1.5",
"hono": "^4.13.14",
"sharp": "^0.35.5"
},
"devDependencies": {
"@types/node": "^26.6.5",
"esbuild": "^0.28.2",
"oxfmt": "^0.75.0"
}
}src/index.ts:
import { serve } from "@hono/node-server";
import { Hono } from "hono";
const app = new Hono();
app.get("/", async (c) => {
try {
const { default: sharp } = await import("sharp");
const png = await sharp({ create: { width: 1, height: 1, channels: 3, background: "#f00" } })
.png()
.toBuffer();
return c.json({ ok: true, arch: process.arch, size: png.byteLength });
} catch (e) {
// @ts-ignore
return c.json({ ok: false, arch: process.arch, error: String(e?.message ?? e) }, 500);
}
});
const address = process.env.AWS_LAMBDA_HTTP_ENDPOINT ?? "0.0.0.0:3000";
const [hostname, port] = address.split(":");
serve({
fetch: app.fetch,
port: Number(port),
hostname,
});Then:
sam build --template-file sam.yml --use-container --debug
ls .aws-sam/build/WebFunction/node_modules/@img/
sam deploy --guided
curl <EndpointUrl>/Observed result:
The build uses the x86_64 image (sam build --use-container --debug, excerpt):
Building codeuri: /path/to/project runtime: nodejs24.x architecture: x86_64 functions: WebFunction
Fetching public.ecr.aws/sam/build-nodejs24.x:latest-x86_64 Docker container image......
The artifact only has Linux x64 binaries:
$ ls .aws-sam/build/WebFunction/node_modules/@img/
colour sharp-libvips-linux-x64 sharp-linux-x64
The deployed Web Function runs on arm64 and can't load sharp:
{
"ok": false,
"arch": "arm64",
"error": "Could not load the \"sharp\" module using the linux-arm64 runtime\nPossible solutions:\n- Ensure optional dependencies can be installed:\n npm install --include=optional sharp\n- Ensure your package manager supports multi-platform installation:\n See https://sharp.pixelplumbing.com/install#cross-platform\n- Add platform-specific dependencies:\n npm install --os=linux --cpu=arm64 sharp\n- Consult the installation documentation:\n See https://sharp.pixelplumbing.com/install"
}Expected result:
sam build builds Web Functions for arm64, the only architecture they run on. With --use-container, it uses the latest-arm64 build image, the same as for an AWS::Serverless::Function with Architectures: [arm64], so native dependencies get Linux arm64 binaries.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Linux (kernel 6.8.0, glibc 2.39), x86_64, Docker v29.9.2
sam --version: 1.170.0- AWS region: ap-northeast-1
{
"version": "1.170.0",
"system": {
"python": "3.15.2",
"os": "Linux-6.8.0-147-generic-x86_64-with-glibc2.39"
},
"additional_dependencies": {
"container_engine": "Docker(v29.9.2)",
"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_PACKAGE_PERFORMANCE",
"SAM_CLI_BETA_UV_PACKAGE_MANAGER"
]
}
Activity
seshubaws commentedon Oct 28, 2026
Ah my mistake, that comment should have said LWF only runs on arm, not x86. Thank you for raising this issue, we will merge and release the fix asap!
github-actions commentedon Oct 28, 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.
fix: build Web Functions for arm64 (aws#9379)