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:
- Enable lifecycle hooks for terminating EC2 instances.
- 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.
- 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.
How are EBS volumes in an unhealthy instance handled when a new instance is created by Auto Scaling?Accepted Answerasked 2 years ago
Auto-scaling is not working with Neptune cluster except when primary writer instance type db.r5d.xlarge.asked 3 months ago
Can't Terminate my EC2 Instanceasked 2 years ago
Healthcheck latency between AWS Auto Scaling and Application Load BalancerAccepted Answerasked 8 months ago
Spot Instance interruption while CodeDeploy is running a deployment to an Auto Scaling groupAccepted AnswerEXPERTasked 2 years ago
Auto Scaling Groups, Launch Template and EC2 instance with multiple ENIs with different configurations.asked 2 months ago
EC2 Auto Scaling group - Spot default maximum price when using multiple instance typesAccepted Answerasked 2 years ago
I have not connect ec2 instance by instance and ssh keyasked 7 months ago
Is it redundant to have an EC2 instance and its EBS volumes in the same AWS Backup resource assignment?Accepted Answerasked 9 months ago
A new EC2 instance is created after termination of the only instanceAccepted Answerasked 2 years ago