Building AWS SAM Runtime Images
A reusable Harness pipeline to build customized AWS SAM images.
This page provides a Harness CD pipeline to help you build your own Docker images for the AWS SAM CLI.
The purpose of this pipeline is to give you flexibility—so you can adopt newer AWS Lambda runtimes or tailor the image to your specific serverless application needs.
What This Pipeline Does
This pipeline automates building AWS SAM images for different programming languages using Harness. It enables you to keep up with the latest SAM versions and apply customizations as required for your projects.
You can find the full pipeline YAML in the Pipeline YAML section below.
Understanding SAM Runtimes
SAM runtimes refer to the programming language environments that AWS Serverless Application Model (SAM) supports for Lambda function development. Each runtime provides the necessary language-specific libraries, tools, and dependencies needed to build, test, and deploy serverless applications.
Common SAM runtimes include:
Node.js: Versions like nodejs18.x, nodejs20.x
Python: Versions like python3.9, python3.10, python3.11
Java: Versions like java11, java17
Ruby: Versions like ruby3.2
Go: Versions like go1.x
When you build your own image using the Harness pipeline, you're combining the Harness SAM base image (which provides the integration with Harness CD) with a specific SAM runtime image from AWS. This allows you to deploy serverless applications written in your preferred programming language while leveraging Harness deployment capabilities.
Key Components and pre-requisites
This pipeline helps you build custom AWS SAM images using Harness, integrating the Harness SAM image with supported AWS Lambda runtimes. Key details about the pipeline include:
Deployment Stage with Kubernetes Infrastructure
Uses a Deployment stage configured to run on Kubernetes.
Privileged Mode and Kubernetes Cluster Setup
The pipeline requires privileged mode enabled on the Kubernetes step group to support Docker-in-Docker (DinD) for building and pushing images.
This mode grants necessary permissions to install and run Docker CLI commands and access the Docker daemon inside pipeline containers.
When using managed Kubernetes services like GKE, do not use Autopilot clusters, which restrict privileged containers.
Instead, use standard clusters with node pools configured to permit privileged pods.
Connect your Kubernetes cluster to Harness via a Kubernetes Cluster connector with appropriate permissions.
Use of Official AWS SAM Images
Pulls SAM base images exclusively from the AWS ECR public gallery for compatibility.
Automatic Extraction of Runtime and Version
The pipeline extracts runtime and version details directly from the SAM base image name.
Final Image Naming Convention
The final built images follow the pattern:
aws-sam-plugin:{VERSION}-{SAM_RUNTIME}-{SAM_VERSION}-linux-amd64Example:aws-sam-plugin:1.1.2-nodejs18.x-1.143.0-linux-amd64
Pipeline Runner Privileged Mode Requirement
Certain steps in the pipeline require the Kubernetes pod to run in privileged mode. This is necessary for starting Docker daemons (DinD), building container images inside pipeline steps, and granting the permissions Docker needs at runtime.
Why privileged mode is required:
Enables Docker-in-Docker (DinD) support for building and pushing images.
Allows installation and execution of docker CLI and manipulation of containers within the build step.
Required for root access and mounting Docker volumes.
To enable privileged execution, set privileged: true in the step group or step-level security context. Example:
For individual steps:
Without this setting, Docker builds and image pushes may fail due to insufficient permissions inside the container.
Quick Start
Copy the provided pipeline YAML and paste it in your Harness Project.
Add an empty/do-nothing service to the pipeline.
Add a Kubernetes environment to the pipeline.
In the Execution section, enable container-based execution in the step group. Add the Kubernetes cluster connector inside the container step group. Save the pipeline.
Click Run Pipeline.
Enter the required parameters:
VERSION: Version number for your plugin (e.g.,
1.1.2). With each new code change, a new tag and Docker image are published, letting users access specific plugin versions. . You can find the Harness base image on Harness DockerHubSAM_BASE_IMAGE: SAM base image from AWS ECR Gallery (e.g.,
public.ecr.aws/sam/build-nodejs18.x:1.143.0-20250502200316-x86_64).
Base Image Requirements
Only official AWS SAM build images from the AWS ECR Public Gallery are supported.
Only use SAM base images from: AWS ECR Gallery - SAM
Only
x86_64architecture images are supportedUsing different base images may cause library dependency issues
Non-standard base images may cause the plugin to not function as required
SAM Base Image Format
The pipeline supports only full formats for the SAM base image:
Full Format: public.ecr.aws/sam/build-nodejs18.x:1.143.0-20250502200316-x86_64
Image Configuration
The final image follows this naming pattern:
Example:
Where:
VERSION: Harness base image (e.g.,1.1.2)SAM_RUNTIME: Runtime extracted from SAM base image (e.g.,nodejs18.x)SAM_VERSION: Version extracted from SAM base image (e.g.,1.143.0)
Variables Used in Pipeline
These variables are actively used in the pipeline for building and pushing the image that you need to configure:
Pipeline variables: - TARGET_REPO, DOCKER_USERNAME, and DOCKER_PASSWORD are set once as pipeline-level variables.
TARGET_REPO
Target Docker repository
your_account/aws-sam-plugin
Yes
DOCKER_USERNAME
Docker registry username
your_dockerhub_username
Yes
DOCKER_PASSWORD
Docker registry password/token
your_dockerhub_pat
Yes
Runtime inputs:
VERSION
Harness base image-version tag
1.1.2
Yes
Harness_BASE_IMAGE
Reference to your built base image
harness/aws-sam-plugin:1.1.2-beta-base-image
Yes
SAM_BASE_IMAGE
AWS SAM base image from ECR
public.ecr.aws/sam/build-python3.12:1.143.0-20250822194415-x86_64
Yes
Pipeline YAML
This is the YAML for the AWS CDK image build pipeline. You can copy and paste it into your Harness Project.
This is how the stage would look in the UI:

Last updated
Was this helpful?