Build AWS CDK runtime images
A reusable Harness pipeline to help you build customized AWS CDK plugin images.
This topic provides a Harness Continuous Delivery (CD) pipeline that you can use to build custom Docker images for the AWS Cloud Development Kit (AWS CDK) plugin. The pipeline gives you the flexibility to use newer AWS CDK versions or customize runtime environments to meet your application requirements.
The pipeline builds a separate AWS CDK plugin Docker image for each supported runtime (Python, Java, .NET, and Go) and pushes the images to your Docker repository. You can use this pipeline to build images with an AWS CDK version newer than the version available in the prebuilt Harness images, or to include additional dependencies required by your CDK application.
Go to the Pipeline YAML section to copy the full pipeline.
What will you learn in this topic?
Understand the prerequisites for running the pipeline.
Which runtimes and base images the pipeline supports.
How the pipeline steps build and push each image.
How to enable privileged mode for the image build steps.
How to run the pipeline and set its variables and runtime inputs.
Before you begin
Kubernetes cluster and connector: Set up a Kubernetes cluster using
KubernetesDirectinfrastructure that allows privileged containers, and a Harness Kubernetes Cluster connector that references it. For managed Kubernetes such as GKE, do not use GKE Autopilot clusters; use a standard node pool that allows privileged mode. Go to Kubernetes Cluster connector settings reference to configure the connector.Docker registry and Git connectors: Configure connectors for Docker registries (
account.dockerhubor your own) and any required Git repositories.Secrets and variables: Store Docker registry credentials and secret variables in Harness secrets management.
Pipeline variables: Be ready to set variables such as
VERSION,AWS_CDK_VERSION,ARCH, andTARGET_REPOat runtime or with defaults.Base scratch image: The pipeline pulls the base scratch image
harness/aws-cdk-plugin:<VERSION>-base-<ARCH>. Confirm this tag exists for your chosenVERSIONon Docker Hub before you run the build.
Go to AWS CDK on npm to find the latest CDK version.
Supported runtimes and base images
The pipeline builds images for the following runtime environments:
Python: Python3, pip, bash, curl, git, Node.js 20, AWS CDK CLI
Java: OpenJDK 11, Maven 3.9.11, bash, curl, git, Node.js 20, AWS CDK CLI
DotNet: .NET runtime and dependencies, bash, icu-libs, git, Node.js 20, AWS CDK CLI
Go: Bash, curl, git, Node.js 20, AWS CDK CLI
All runtime images derive from the supported Harness base plugin images and runtime-specific Node.js OS base images.
The pipeline tags each image it builds in the format <TARGET_REPO>:<RUNTIME>-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>, for example harness/aws-cdk-plugin:python-1.4.0-2.1029.1-linux-amd64.
Pipeline steps and execution flow
The pipeline runs the following steps to build and push each runtime image:
Authentication setup: Creates the Docker config for registry authentication.
Dockerfile generation: Generates Dockerfiles per runtime, each of which uses a multi-stage build (base plus runtime image), copies the plugin and scripts from the base image, installs the language runtime and AWS CDK, and configures Node.js, metadata, and the entrypoint.
Image build and push: Uses Docker to build and push the tagged runtime images.
Privileged mode requirement
Certain pipeline steps, such as Docker-in-Docker for image build and push, require privileged execution. Privileged steps are not standard pipeline steps; they run with escalated permissions and must be explicitly enabled with privileged: true in the pipeline YAML.
To enable privileged mode, set privileged: true under spec in your step group or individual step. Your Kubernetes cluster must be configured to allow privileged containers.
For individual steps:
Without this setting, Docker builds and image pushes can fail due to insufficient permissions inside the container.
Run the image build pipeline
Perform the following steps to run the image build pipeline:
Copy the pipeline YAML into your Harness project.
Add an empty do-nothing service to the pipeline.
Configure a Kubernetes environment in Harness.
In the Execution section, enable container-based execution in the step group. Add the Kubernetes Cluster connector inside the container step group, then save the pipeline.
Select Run Pipeline.
Fill in all required variables. Go to Pipeline variables and runtime inputs to review each variable.
Pipeline variables and runtime inputs
Set the following variables in the pipeline YAML and at runtime.
Pipeline variables
The following variables are set in the pipeline YAML:
TARGET_REPO
Docker repository
harness/aws-cdk-plugin
DOCKER_USERNAME
Docker registry username
your-dockerhub-username
DOCKER_PASSWORD
Docker registry password or token
From secrets
Runtime inputs
The following variables are supplied at runtime:
VERSION
Harness base image version
1.4.0
AWS_CDK_VERSION
AWS CDK CLI version
2.1029.1
ARCH
Image build architecture
amd64 or arm64

Pipeline YAML
The following YAML defines the AWS CDK image build pipeline. Copy and paste it into your Harness project.
The stage renders in the UI as shown below:

Output images
After a successful build, you have four tagged images in your target Docker repository. Each tag follows the format the pipeline builds, <TARGET_REPO>:<RUNTIME>-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>:
Python:
<TARGET_REPO>:python-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>Java:
<TARGET_REPO>:java-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>DotNet:
<TARGET_REPO>:dotnet-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>Go:
<TARGET_REPO>:go-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>
Each image includes the required runtime, the AWS CDK CLI, and the Harness plugin, ready for production use.
Related topics
Go to AWS CDK Provisioning to configure CDK steps that run on your custom images.
Go to AWS CDK use cases and examples to review provisioning modes and code examples.
Last updated
Was this helpful?