Skip to content

lambda: default architecture X86_64 isn't used for cross-platform docker builds #31048

@tabrezm

Description

@tabrezm

Describe the bug

The current documented behavior for the architecture prop on lambda_.DockerImageFunction is:

architecture: The system architectures compatible with this lambda function. Default: Architecture.X86_64

However, I found running cdk deploy on my Mac would not target amd64. This results in the following error message when invoking the deployed Lambda function:

Error: fork/exec /lambda-entrypoint.sh: exec format error Runtime.InvalidEntrypoint

I was able to resolve this by explicitly setting:

lambda_.DockerImageFunction(self, ..., architecture=lambda_.Architecture.X86_64)

Another quirk I found was that specifying --platform in build_args is silently ignored. You can only specify this setting via the platform property.

code=lambda_.DockerImageCode.from_image_asset(
    directory=...,
    build_args={"--platform": "linux/amd64"},  # doesn't work
    platform=ecr_assets.Platform.LINUX_X86_64,  # works
),

Expected Behavior

  1. The lambda_.DockerImageFunction() default architecture of lambda_.Architecture.X86_64 is passed to docker build
  2. Allow passing --platform in build_args or raise an error

Current Behavior

The default value either seems to not be set correctly, or it's not passed correctly to docker build.

Reproduction Steps

Follow the hello world example here.

lambda_.DockerImageFunction(
            self,
            "HelloWorldLambda",
            code=lambda_.DockerImageCode.from_image_asset(
                directory=...,
                # build_args={"--platform": "linux/amd64"},
                # platform=ecr_assets.DockerPlatform.LINUX_X86_64,
            ),
            # architecture=lambda_.Architecture.X86_64,
        )

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.151.0 (build b8289e2)

Framework Version

No response

Node.js Version

v20.16.0

OS

macOS

Language

Python

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-lambdaRelated to AWS LambdabugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions