All about Cloud, mostly about Amazon Web Services (AWS)

Termination Protection Gotcha!

 2017-12-06 /  430 words /  3 minutes

Termination Protection is a feature designed to prevent accidental deletion of AWS resources. The AWS Management Console added support for Termination protection for Amazon Elastic Compute Cloud (EC2) instances has been around since 2011. The concept is simple. The resource has a flag. The AWS API checks the flag before deleting the resource. If the flag is set the deletion fails.

AWS API calls exist to set and reset the flag. From the AWS Command Line Interface (CLI) tool, the modify-instance-attributes (https://docs.aws.amazon.com/cli/latest/reference/ec2/modify-instance-attribute.html) command changes the value of the flag.

Termination Protection Gotcha!

An Auto Scaling group contained two EC2 instances. While I’m usually a huge advocate of automation and immutable infrastructure, one of those instances requires a long tedious manual configuration process which relied on favors from other teams. It wasn’t possible to ask for their help to reconfigure the other instance in the same way, but without those modifications, the application wouldn’t run properly. Success or failure would depend on where the Application Load Balancer (ALB) routed the traffic. I also didn’t want to have an EC2 instance sitting around unused.

I remembered that I could use termination protection and then reduce the Auto Scaling group min, max and desired count from two to one. The documentation, found here, stated:

You can also use instance protection to prevent Auto Scaling from selecting specific instances for termination when scaling in.

The manually configured EC2 instance was identified then EC2 Termination Protection was set. I then reduced the Auto Scaling group counts and watched the AWS Console with horror as my manually configured EC2 instance was shutdown.

The Postmortem

I quickly tried a few things to see if I could interrupt the process, but nothing prevented the loss of that instance. I went back to the documentation and read it again more carefully. The documentation stated:

To change the instance protection setting for an instance using the console

Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. On the navigation pane, choose Auto Scaling Groups. Select the Auto Scaling group. On the Instances tab, select the instance. To enable instance protection, choose Actions, Instance Protection, Set Scale In Protection. When prompted, choose Set Scale In Protection. The termination protection process for Auto Scaling groups was completely different from the termination protection process for EC2 instances! From the Auto Scaling groups part of the AWS Console, “Scale In Protection” replaces “termination protection“.

There’s a saying “A smart man learns from his own mistakes, but a wise man learns from someone else’s“. I certainly have learned from this, and I hope you have learned too!


Tags:  AWS  Amazon Elastic Compute Cloud (EC2)
Categories:  AWS  Compute  Amazon Elastic Compute Cloud (EC2)

See Also

 Top Ten Tags

AWS (43)   Kinesis (9)   Streams (8)   AWS Console (5)   Go (5)   Analytics (4)   Data (4)   database (4)   Amazon DynamoDB (3)   Amazon Elastic Compute Cloud (EC2) (3)  


All Tags (173)

Disclaimer

All data and information provided on this site is for informational purposes only. cloudninja.cloud makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis.

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. My opinions may change over time.