How are EBS volumes in an unhealthy instance handled when a new instance is created by Auto Scaling?

0

Suppose that my Amazon EC2 instance turns unhealthy, and AWS Auto Scaling replaces this instance with a new EC2 instance. Can you explain which one of the following happens In this case? Are the Amazon EBS volumes attached to the unhealthy instance transferred to the new EC2 instance created? -or- Does the launch configuration create new EBS volumes and attach them to the new EC2 instance?

I've also looked at [adding EC2 recover actions through Amazon CloudWatch alarms][1], but I'm not sure how this feature works when the instance is associated with an Auto Scaling group.

My intent is to have the existing EBS volumes attached to the new EC2 instance so that the application running on the instance can use the data and filesystems that existed before the instance turned unhealthy. [1]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UsingAlarmActions.html#AddingRecoverActions

2 Answers
0
Accepted Answer

You can use the Auto Scaling Lifecycle hooks that enable you to perform custom actions by pausing instances when an Auto Scaling group launches or terminates them. For your use case, you can do the following:

  1. Enable lifecycle hooks for terminating EC2 instances.
  2. When the instance is in the Terminating Wait state, perform a custom action using an AWS lambda function, where you can take the respective instance snapshot.
  3. After the above action is successful, you can call the complete-lifecycle-action API.

You can attach a secondary elastic network interface to the terminating instance using EC2 Auto Scaling. For more information, see Creating a launch template for an Auto Scaling group. Also, you can create the snapshot of this instance using the AWS CLI.

In your AWS Lambda function, you can create a new launch configuration with this latest configuration and update the Auto Scaling group to use new configuration. When the new instance is launched, it inherits the new configuration.

AWS
answered 4 years ago
  • This answer is at a very high level. Some more detail will be definitely needed, so that it can help others.

0

Can you please provide some reference links or examples or documentation supporting your answer? I am relatively new to this. Some links/examples will help a lot.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions