aws-samples
cdk-image-pipeline
TypeScript

L3 construct that can be used to quickly deploy a complete EC2 Image Builder Image Pipeline

Last updated Jun 19, 2026
46
Stars
14
Forks
8
Issues
0
Stars/day
Attention Score
50
Language breakdown
TypeScript 86.8%
Python 9.1%
JavaScript 4.1%
Files click to expand
README

npm version PyPI version GitHub version

CDK Image Pipeline


L3 construct that can be used to quickly deploy a complete EC2 Image Builder Image Pipeline.

This construct creates the required infrastructure for an Image Pipeline:

  • Infrastructure configuration which specifies the infrastructure within which to build and test your EC2 Image Builder image.
  • An instance profile associated with the infrastructure configuration
  • An EC2 Image Builder recipe defines the base image to use as your starting point to create a new image, along with the set of components that you add to customize your image and verify that everything is working as expected.
  • Image Builder uses the AWS Task Orchestrator and Executor (AWSTOE) component management application to orchestrate complex workflows. AWSTOE components are based on YAML documents that define the scripts to customize or test your image. Support for multiple components.
  • Image Builder image pipelines provide an automation framework for creating and maintaining custom AMIs and container images.

Install


NPM install:

npm install cdk-image-pipeline

PyPi install:

<pre><code class="lang-sh">pip install cdk-image-pipeline</code></pre>

Usage


<pre><code class="lang-typescript">import { ImagePipeline } from &#39;cdk-image-pipeline&#39; import { Construct } from &#39;constructs&#39;;

// ... // Create a new image pipeline with the required properties new ImagePipeline(this, &quot;MyImagePipeline&quot;, { components: [ { document: &#39;component_example.yml&#39;, name: &#39;Component&#39;, version: &#39;0.0.1&#39;, }, { document: &#39;componentexample2.yml&#39;, name: &#39;Component2&#39;, version: &#39;0.1.0&#39;, }, ], parentImage: &#39;ami-0e1d30f2c40c4c701&#39;, ebsVolumeConfigurations: [ { deviceName: &#39;/dev/xvda&#39;, ebs: { encrypted: true, iops: 200, kmsKeyId: &#39;alias/app1/key&#39;, volumeSize: 20, volumeType: &#39;gp3&#39;, throughput: 1000, }, }, ], }) // ...</code></pre>

By default, the infrastructure configuration will deploy EC2 instances for the build/test phases into a default VPC using the default security group. If you want to control where the instances are launched, you can specify an existing VPC SubnetID and a list of SecurityGroupIds. In the example below, a new VPC is created and referenced in the ImagePipeline construct object.

<pre><code class="lang-typescript">import { ImagePipeline } from &#39;cdk-image-pipeline&#39; import * as ec2 from &#39;aws-cdk-lib/aws-ec2&#39;; import { Construct } from &#39;constructs&#39;;

// ... // create a new VPC const vpc = new ec2.Vpc(this, &quot;Vpc&quot;, { cidr: &quot;10.0.0.0/16&quot;, maxAzs: 2, subnetConfiguration: [ { cidrMask: 24, name: &#39;ingress&#39;, subnetType: ec2.SubnetType.PUBLIC, }, { cidrMask: 24, name: &#39;imagebuilder&#39;, subnetType: ec2.SubnetType.PRIVATEWITHNAT, }, ] });

// create a new security group within the VPC const sg = new ec2.SecurityGroup(this, &quot;SecurityGroup&quot;, { vpc:vpc, });

// get the private subnet from the vpc const private_subnet = vpc.privateSubnets;

new ImagePipeline(this, &quot;MyImagePipeline&quot;, { components: [ { document: &#39;component_example.yml&#39;, name: &#39;Component&#39;, version: &#39;0.0.1&#39;, }, { document: &#39;componentexample2.yml&#39;, name: &#39;Component2&#39;, version: &#39;0.1.0&#39;, }, ], parentImage: &#39;ami-0e1d30f2c40c4c701&#39;, securityGroups: [sg.securityGroupId], subnetId: private_subnet[0].subnetId, }) // ...</code></pre>

Python usage:

<pre><code class="lang-python">from cdkimagepipeline import ImagePipeline from constructs import Construct

...

image_pipeline = ImagePipeline( self, &quot;LatestImagePipeline&quot;, components=[ { document: &#39;component_example.yml&#39;, name: &#39;Component&#39;, version: &#39;0.0.1&#39;, }, { document: &#39;componentexample2.yml&#39;, name: &#39;Component2&#39;, version: &#39;0.1.0&#39;, }, ], parent_image=&quot;ami-0e1d30f2c40c4c701&quot;, )

...</code></pre>

<pre><code class="lang-python">from aws_cdk import ( # Duration, Stack, aws_ec2 as ec2, ) from constructs import Construct from cdkimagepipeline import ImagePipeline

...

create a new VPC

vpc = ec2.Vpc( self, &quot;MyVpcForImageBuilder&quot;, cidr=&quot;10.0.0.0/16&quot;, max_azs=2, subnet_configuration=[ ec2.SubnetConfiguration( name=&quot;Ingress&quot;, subnet_type=ec2.SubnetType.PUBLIC, cidr_mask=24, ), ec2.SubnetConfiguration( name=&quot;ImageBuilder&quot;, subnettype=ec2.SubnetType.PRIVATEWITHNAT, cidrmask=24 ), ], )

create a new security group within the VPC

sg = ec2.SecurityGroup(self, &quot;SG&quot;, vpc=vpc)

get the private subnet from the vpc

privsubnets = vpc.privatesubnets

image_pipeline = ImagePipeline( self, &quot;LatestImagePipeline&quot;, components=[ { document: &#39;component_example.yml&#39;, name: &#39;Component&#39;, version: &#39;0.0.1&#39;, }, { document: &#39;componentexample2.yml&#39;, name: &#39;Component2&#39;, version: &#39;0.1.0&#39;, }, ], parent_image=&quot;ami-0e1d30f2c40c4c701&quot;, securitygroups=[sg.securitygroup_id], subnetid=privsubnets[0].subnet_id )

...</code></pre>

Component Documents


Image Builder uses the AWS Task Orchestrator and Executor (AWSTOE) component management application to orchestrate complex workflows. AWSTOE components are based on YAML documents that define the scripts to customize or test your image.

You must provide a component document in YAML to the ImagePipeline construct. See the example document below:

<pre><code class="lang-yaml">name: MyComponentDocument description: This is an example component document schemaVersion: 1.0

phases: - name: build steps: - name: InstallUpdates action: UpdateOS - name: validate steps: - name: HelloWorldStep action: ExecuteBash inputs: commands: - echo &quot;Hello World! Validate.&quot; - name: test steps: - name: HelloWorldStep action: ExecuteBash inputs: commands: - echo &quot;Hello World! Test.</code></pre>

Multiple Components

To specify multiple components, add additional component documents to the componentDoucments property. You can also add the names and versions of these components via the componentNames and componentVersions properties (See usage examples above). The components will be associated to the Image Recipe that gets created as part of the construct.

Be sure to update the imageRecipeVersion property when making updates to your components after your initial deployment.

SNS Encryption using KMS


Specify a KMS Key via the kmsKey property which will be used to encrypt the SNS topic.

Infrastructure Configuration Instance Types


Infrastructure configuration contain settings for building and testing your EC2 Image Builder image. This construct allows you to specify a list of instance types you wish to use via the instanceTypes property. The default is: ['t3.medium', 'm5.large', 'm5.xlarge']`.

Additional API notes


API Reference

🔗 More in this category

© 2026 GitRepoTrend · aws-samples/cdk-image-pipeline · Updated daily from GitHub