Building ARM64 Infrastructure with CDK Pipelines

When building ARM64 resources with CDK Pipelines, it is necessary to have them built using an ARM64 Image with CodeBuild.

Building ARM64 Infrastructure with CDK Pipelines

When building ARM64 resources with CDK Pipelines, it is necessary to have them built using an ARM64 Image with CodeBuild. Otherwise, you will get an error like this during the Synth action:

[Warning] The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested

To ensure that the image used is an arm64/v8 image, the Typescript code should look like this:

const cdkPipeline = new pipelines.CodePipeline(this, "Pipeline", {
  selfMutation: true,
  dockerEnabledForSelfMutation: true,
  dockerEnabledForSynth: true,
  synth: new pipelines.ShellStep("Synth", {
    input: pipelines.CodePipelineSource.connection(
      "repo/cdk-pipeline-deployment",
      "main",
      {
        connectionArn:
          "arn:aws:codestar-connections:us-east-2:xxxxxxxxxxx:connection/xxxxxxx-7d1c-453c-xxxx-1c73586de313",
      },
    ),
    commands: ["npm ci", "npm run build", "npx cdk synth"],
  }),
  synthCodeBuildDefaults: {
    buildEnvironment: {
      computeType: codebuild.ComputeType.LARGE,
      buildImage: codebuild.LinuxBuildImage.AMAZON_LINUX_2_ARM,
    },
  },
  assetPublishingCodeBuildDefaults: {},
  selfMutationCodeBuildDefaults: {},
  codeBuildDefaults: {},
});

At this point, Stages can be added with :

cdkPipeline.addStage(...)

This is a self-mutating build. However, if you add the Stage with ARM64 resources before adding the synthCodeBuildDefaults, it will fail. To mutate the pipeline to allow the Stage to be built, remove the Stage, add the buildEnvironment parameters, rebuild the pipeline, add the Stage back, and rebuild the pipeline again. Now this pipeline should use the correct image when building the ARM64 resources.