Codedeploy fails when autoscaling group is empty

0

The application is running on several machines within the autoscaling group. Usually we roll out changes one machine at a time using codedeploy, but sometimes we need a complete application stop before deploying an incompatible change. Note that just stopping the traffic is not enough, we need a complete shutdown of all nodes before deploying a new version.

I have tried to scale down the autoscaling group to 0 instances, but in this case CodeDeploy cannot register the new version because it sees no instances to proceed with the deployment. Is there any other way to make CodeDeploy deploy another version of the application next time it scales?

Basically what I want:

  1. Application completely shuts down.
  2. Some actions are running like db migration.
  3. The new version of the application spins up.

What I tried:

  1. Scale autoscaling group to 0 instances.
  2. Deploy a new version through codedeploy (this step fails because there are no running instances).
  3. Set autoscaling group to X to run the new version of the application (this does not work properly, old version spins up).
Valerii
asked 13 days ago163 views
2 Answers
1

As you said, CodeDeploy requires a running instance to deploy successfully to before it will mark the new application revision as good and use it for further deployments.

For your situation where you need to have 0 instances, there's 2 ways to do this:

  • A Blue/Green deployment might work (although, not supported in CFN, so not an option if you're using that)
  • You can configure deployment to an EC2 instance based on a Tag. The deployment would go through, and then you could spin the ASG back up with the new revision getting deployed
AWS
EXPERT
answered 13 days ago
0

Hello,

Please try this solution,

Scale down the Auto Scaling Group to 0 instances:

In the AWS Management Console, go to the EC2 Auto Scaling section.

Select the desired Auto Scaling Group.

Set the desired capacity to 0. This will terminate all running instances in the ASG.

Run the necessary actions (like DB migration):

Ensure that all required pre-deployment actions are executed. This can be done manually or using an automation tool like AWS Systems Manager, AWS Lambda, or a custom script.

Update the Launch Configuration or Launch Template:

If using a Launch Configuration:

Create a new Launch Configuration with the new version of the application.

Update the ASG to use the new Launch Configuration.

If using a Launch Template:

Create a new version of the Launch Template with the new version of the application.

Update the ASG to use the new version of the Launch Template.

Scale up the Auto Scaling Group:

Increase the desired capacity of the ASG to the required number of instances. The ASG will launch new instances using the updated Launch Configuration or Launch Template.

The new instances will have the new version of the application.

https://docs.aws.amazon.com/codedeploy/latest/userguide/integrations-aws-auto-scaling.html

https://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-auto-scaling.html

EXPERT
answered 13 days ago