Skip to content

Wrong SAM container image architecture when trying to build NodeJS lambda #27370

@r007

Description

@r007

Describe the bug

Hello guys,

After recent changes, my cdk deploy stopped working. I have a few lambdas declared as following:

const myLambda = new NodejsFunction(this, 'Example', {
  entry: join(__dirname, `/../../some/path.ts`),
  runtime: Runtime.NODEJS_18_X,
  architecture: Architecture.ARM_64,
  memorySize: 256,
  bundling: {
    minify: true,
    externalModules: ['@aws-sdk/client-dynamodb']
  }
})

I use architecture: Architecture.ARM_64 to save some costs. On my desktop machine I have Ubuntu Linux (amd64 architecture). So when I type cdk deploy MyStack it launches sam build command for every lambda function. Docker images are starting to download, I see the following line:

--> Command: docker build -t cdk-e46d15a7662e461d1d19a3c4b3874cda9ae1d1d3f77bb3e2068a7e2c5d164204 --platform "linux/arm64" --build-arg "IMAGE=public.ecr.aws/sam/build-nodejs18.x" --build-arg "ESBUILD_VERSION=0" "/home/r007/Projects/my-project/node_modules/aws-cdk-lib/aws-lambda-nodejs/lib"

Notice the --platform "linux/arm64" flag.

It fails on the very first command:

 > [ 2/10] RUN npm install --global yarn@1.22.5:
0.333 exec /bin/sh: exec format error

Because of the incompatibility of ARM64 architecture with AMD64.

Expected Behavior

It should not use target architecture for building JavaScript code. It worked just fine before I updated cdk dependency.

Current Behavior

It fails with error message exec /bin/sh: exec format error

Reproduction Steps

  1. Create NodejsFunction with any content.
  2. Use architecture: Architecture.ARM_64.
  3. Do cdk deploy.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.99.1 (build b2a895e)

Framework Version

No response

Node.js Version

v18.17.1

OS

Ubuntu 22.04.3 LTS

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-samRelated to AWS Serverless Application ModelbugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions