Skip to content

asset-staging.ts: target platform ignored when bundling asset #30239

Closed
@t3r

Description

@t3r

Describe the bug

When bundling an asset e.g. in an s3_deployment using docker, the platform property gets ignored. The bundling always takes place on the host's platform.

Expected Behavior

Using
platform: 'linux/amd64'
should bundle for amd64 on M1 and
platform: 'linux/arm64'
should bundle for ARM on amd64 architecture as described in https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.BundlingOptions.html#platform

Current Behavior

platform: 'something' is silently ignored.

Reproduction Steps

Bundle for a s3_deployment like this:

new s3_deployment.BucketDeployment(this, 'platform-bug', {
      sources: [s3_deployment.Source.asset('.', {
        bundling: {
          image: lambda.Runtime.PYTHON_3_9.bundlingImage,
          platform: 'linux/amd64',
          //platform: 'linux/arm64',
          command: [
            'bash', '-c',
            'uname -m > /asset-output/uname-m.out.txt'
          ],
        },
      })],
      destinationBucket: bucket,
      destinationKeyPrefix: 'test',
    })

Do a cdk synthesize and look into the created output file 'uname-m.out.txt' asset in cdk.out. Whatever you put into 'platform', it always contains your host machine's platform string.

Possible Solution

The reason is that the platform given does not get propagated in aws-cdk-lib/core/lib/private/asset-staging.ts when calling image.run().
adding platform: this.options.platform at two places fixes the issue.
Pull request is on it's way.

Additional Information/Context

No response

CDK CLI Version

2.141.0 (build 3d1c06e)

Framework Version

No response

Node.js Version

v20.11.0

OS

macos 14.4.1 (23E224)

Language

TypeScript

Language Version

No response

Other information

As a sidenote: before changing the platform, the local docker build image, e.g. public.ecr.aws/sam/build-python3.9:latest has to be deleted manually using docker image rm public.ecr.aws/sam/build-python3.9:latest. Otherwise docker would use the same image for a different/wrong platform with unwanted behavior.
Fixing that is not within the scope of this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions