Package: cloudcomponents.cdk-blue-green-container-deployment
@cloudcomponents/cdk-blue-green-container-deploymentBlue green container deployment with CodeDeployInstallTypeScript/JavaScript:npmi@cloudcomponents/cdk-blue-green-container-deploymentPython:pipinstallcloudcomponents.cdk-blue-green-container-deploymentHow to useimport{EcsService,DummyTaskDefinition,EcsDeploymentGroup,PushImageProject}from'@cloudcomponents/cdk-blue-green-container-deployment';import{ImageRepository}from'@cloudcomponents/cdk-container-registry';import{Duration,Stack,StackProps}from'aws-cdk-lib';import{Repository}from'aws-cdk-lib/aws-codecommit';import{Pipeline,Artifact}from'aws-cdk-lib/aws-codepipeline';import{CodeBuildAction,CodeCommitSourceAction,CodeDeployEcsDeployAction}from'aws-cdk-lib/aws-codepipeline-actions';import{Vpc,Port}from'aws-cdk-lib/aws-ec2';import{Cluster}from'aws-cdk-lib/aws-ecs';import{ApplicationLoadBalancer,ApplicationTargetGroup,TargetType}from'aws-cdk-lib/aws-elasticloadbalancingv2';import{Construct}from'constructs';exportclassBlueGreenContainerDeploymentStackextendsStack{constructor(scope:Construct,id:string,props?:StackProps){super(scope,id,props);constvpc=newVpc(this,'Vpc',{maxAzs:2,});constcluster=newCluster(this,'Cluster',{vpc,clusterName:'blue-green-cluster',});constloadBalancer=newApplicationLoadBalancer(this,'LoadBalancer',{vpc,internetFacing:true,});constprodListener=loadBalancer.addListener('ProfListener',{port:80,});consttestListener=loadBalancer.addListener('TestListener',{port:8080,});constprodTargetGroup=newApplicationTargetGroup(this,'ProdTargetGroup',{port:80,targetType:TargetType.IP,vpc,});prodListener.addTargetGroups('AddProdTg',{targetGroups:[prodTargetGroup],});consttestTargetGroup=newApplicationTargetGroup(this,'TestTargetGroup',{port:8080,targetType:TargetType.IP,vpc,});testListener.addTargetGroups('AddTestTg',{targetGroups:[testTargetGroup],});//WillbereplacedbyCodeDeployinCodePipelineconsttaskDefinition=newDummyTaskDefinition(this,'DummyTaskDefinition',{image:'nginx',family:'blue-green',});constecsService=newEcsService(this,'EcsService',{cluster,serviceName:'blue-green-service',desiredCount:2,taskDefinition,prodTargetGroup,testTargetGroup,});ecsService.connections.allowFrom(loadBalancer,Port.tcp(80));ecsService.connections.allowFrom(loadBalancer,Port.tcp(8080));constdeploymentGroup=newEcsDeploymentGroup(this,'DeploymentGroup',{applicationName:'blue-green-application',deploymentGroupName:'blue-green-deployment-group',ecsServices:[ecsService],targetGroups:[prodTargetGroup,testTargetGroup],prodTrafficListener:prodListener,testTrafficListener:testListener,terminationWaitTime:Duration.minutes(100),});//@seefiles:./blue-green-repositoryforexamplecontentconstrepository=newRepository(this,'CodeRepository',{repositoryName:'blue-green-repository',});constimageRepository=newImageRepository(this,'ImageRepository',{forceDelete:true,//Onlyfortests});constsourceArtifact=newArtifact();constsourceAction=newCodeCommitSourceAction({actionName:'CodeCommit',repository,output:sourceArtifact,});constimageArtifact=newArtifact('ImageArtifact');constmanifestArtifact=newArtifact('ManifestArtifact');constpushImageProject=newPushImageProject(this,'PushImageProject',{imageRepository,taskDefinition,});constbuildAction=newCodeBuildAction({actionName:'PushImage',project:pushImageProject,input:sourceArtifact,outputs:[imageArtifact,manifestArtifact],});constdeployAction=newCodeDeployEcsDeployAction({actionName:'CodeDeploy',taskDefinitionTemplateInput:manifestArtifact,appSpecTemplateInput:manifestArtifact,containerImageInputs:[{input:imageArtifact,taskDefinitionPlaceholder:'IMAGE1_NAME',},],deploymentGroup,});newPipeline(this,'Pipeline',{pipelineName:'blue-green-pipeline',stages:[{stageName:'Source',actions:[sourceAction],},{stageName:'Build',actions:[buildAction],},{stageName:'Deploy',actions:[deployAction],},],});}}API ReferenceSeeAPI.md.ExampleSee more completeexamples.LicenseMIT