Package: cdk-image-pipeline
CDK Image PipelineL3 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 configurationAn 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.InstallNPM install:npminstallcdk-image-pipelinePyPi install:pipinstallcdk-image-pipelineUsageimport{ImagePipeline}from'cdk-image-pipeline'import{Construct}from'constructs';//...//CreateanewimagepipelinewiththerequiredpropertiesnewImagePipeline(this,"MyImagePipeline",{components:[{document:'component_example.yml',name:'Component',version:'0.0.1',},{document:'component_example_2.yml',name:'Component2',version:'0.1.0',},],parentImage:'ami-0e1d30f2c40c4c701',ebsVolumeConfigurations:[{deviceName:'/dev/xvda',ebs:{encrypted:true,iops:200,kmsKeyId:'alias/app1/key',volumeSize:20,volumeType:'gp3',throughput:1000,},},],})//...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 VPCSubnetIDand a list ofSecurityGroupIds. In the example below, a new VPC is created and referenced in theImagePipelineconstruct object.import{ImagePipeline}from'cdk-image-pipeline'import*asec2from'aws-cdk-lib/aws-ec2';import{Construct}from'constructs';//...//createanewVPCconstvpc=newec2.Vpc(this,"Vpc",{cidr:"10.0.0.0/16",maxAzs:2,subnetConfiguration:[{cidrMask:24,name:'ingress',subnetType:ec2.SubnetType.PUBLIC,},{cidrMask:24,name:'imagebuilder',subnetType:ec2.SubnetType.PRIVATE_WITH_NAT,},]});//createanewsecuritygroupwithintheVPCconstsg=newec2.SecurityGroup(this,"SecurityGroup",{vpc:vpc,});//gettheprivatesubnetfromthevpcconstprivate_subnet=vpc.privateSubnets;newImagePipeline(this,"MyImagePipeline",{components:[{document:'component_example.yml',name:'Component',version:'0.0.1',},{document:'component_example_2.yml',name:'Component2',version:'0.1.0',},],parentImage:'ami-0e1d30f2c40c4c701',securityGroups:[sg.securityGroupId],subnetId:private_subnet[0].subnetId,})//...Python usage:fromcdk_image_pipelineimportImagePipelinefromconstructsimportConstruct# ...image_pipeline=ImagePipeline(self,"LatestImagePipeline",components=[{document:'component_example.yml',name:'Component',version:'0.0.1',},{document:'component_example_2.yml',name:'Component2',version:'0.1.0',},],parent_image="ami-0e1d30f2c40c4c701",)# ...fromaws_cdkimport(# Duration,Stack,aws_ec2asec2,)fromconsturctsimportConstructfromcdk_image_pipelineimportImagePipeline# ...# create a new VPCvpc=ec2.Vpc(self,"MyVpcForImageBuilder",cidr="10.0.0.0/16",max_azs=2,subnet_configuration=[ec2.SubnetConfiguration(name="Ingress",subnet_type=ec2.SubnetType.PUBLIC,cidr_mask=24,),ec2.SubnetConfiguration(name="ImageBuilder",subnet_type=ec2.SubnetType.PRIVATE_WITH_NAT,cidr_mask=24),],)# create a new security group within the VPCsg=ec2.SecurityGroup(self,"SG",vpc=vpc)# get the private subnet from the vpcpriv_subnets=vpc.private_subnetsimage_pipeline=ImagePipeline(self,"LatestImagePipeline",components=[{document:'component_example.yml',name:'Component',version:'0.0.1',},{document:'component_example_2.yml',name:'Component2',version:'0.1.0',},],parent_image="ami-0e1d30f2c40c4c701",security_groups=[sg.security_group_id],subnet_id=priv_subnets[0].subnet_id)# ...Component DocumentsImage 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 acomponent documentin YAML to theImagePipelineconstruct. See the example document below:name:MyComponentDocumentdescription:This is an example component documentschemaVersion:1.0phases:-name:buildsteps:-name:InstallUpdatesaction:UpdateOS-name:validatesteps:-name:HelloWorldStepaction:ExecuteBashinputs:commands:-echo "Hello World! Validate."-name:teststeps:-name:HelloWorldStepaction:ExecuteBashinputs:commands:-echo "Hello World! Test.Multiple ComponentsTo specify multiple components, add additional component documents to thecomponentDoucmentsproperty. You can also add the names and versions of these components via thecomponentNamesandcomponentVersionsproperties (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 theimageRecipeVersionproperty when making updates to your components after your initial deployment.SNS Encryption using KMSSpecify a KMS Key via thekmsKeyproperty which will be used to encrypt the SNS topic.Infrastructure Configuration Instance TypesInfrastructure configurationcontain 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 theinstanceTypesproperty. The default is:['t3.medium', 'm5.large', 'm5.xlarge'].Additional API notesAPI Reference