How can I implement this type of deployment strategy using CDK?
I wrote a project using cdk python where I can deploy a load balancer, security groups, auto scaling group. It's going to be used as a central common pipeline. The cdk deploy is executed by gitlab. I would like to get some ideas on how I can implement a strategy like this
Let's assume there is already an existing autoscalinggroup deployed by the code I wrote. Let's name it auto-scaling-group-7ea57ea1. The 7ea57ea1 is a git commit sha. Of course there is an ec2 instance or instances provisioned by this ASG.
Here is what I want to happen.
-
When a team does a new deployment, the cdk python must build a brand new auto-scaling group. Let's name the asg auto-scaling-group-9ff0d223.
-
The auto-scaling-group-9ff0d223 provisions new ec2 instances.
-
If the application on the new ec2 instance(s) provisioned by auto-scaling-group-9ff0d223 is healthy, the cdk python code or maybe some outside tooling, must deregister the ec2 instance(s) provisioned by auto-scaling-group-7ea57ea1 from the load balancer. It must not terminate the ec2 instance(s). The code or tool must also register the new asg, 9ff0d223, to the target group.
-
If application on the new ec2 contains some bugs like it's returning wrong results, the developers can switch back to 7ea57ea1 since the ec2 instances were not terminated.
How can I build this deployment strategy in AWS CDK? Right now, my code only supports rolling deployment meaning, every time application is healthy during new deployment, it terminate the previous asg and registers the new asg to the target group.
Any help would be greatly appreciated! Thank you!
Posted Jun 30, 2025, 3:24 AM UTC