How to Find EC2 Instances Scheduled To Retire Soon
Prevent interruptions by checking for scheduled EC2 retirements. Follow these steps to locate and handle retiring EC2 instances effectively.
Prevent interruptions by checking for scheduled EC2 retirements. Follow these steps to locate and handle retiring EC2 instances effectively.
When Amazon Web Services (AWS) detects a failure within the underlying hardware supporting your EC2 instance, it schedules the instance for retirement. If you don’t take the right steps before AWS stops or terminates the instance, your organization risks losing important live services and data at an unexpected time.
While there are notifications issued by AWS, it’s important for your organization to have a process for responding and handling retiring EC2 instances. If you don’t act quickly, then these instances may become unreachable depending on the extent of degradation.
A key part of building an EC2 retirement process is being able to quickly locate all instances with upcoming retirements. It can be difficult to locate all of these instances if you are operating in multiple AWS regions because you will need to run these queries per region. There are tools like Blink that enable an automated method for locating EC2 instances across regions, but for the sake of this guide, we’ll walk you through the steps using the manual approach first.
The primary account holder and operations contacts receive an email from AWS letting them know which instance ID will be retired and the retirement date. You can also look for any instances due for retirement on your Amazon EC2 console or the command line.
To find retiring EC2 instances from the command line, open a terminal and run the following command:
To identify retiring instances when you are reading the output, look for results that have events with “event.code” of “instance_retirement”.
If you start getting error messages when you run the above command, try updating to the latest version of the AWS CLI. Those using AWS Tools for Windows PowerShell can use the following command:
Now that you have a list of upcoming retirements, you should check if your instance is still reachable before the retirement date. First, connect to or ping your retiring EC2 instance to see if there’s a response. If it has already become unreachable, you can try stopping and restarting the instance. If it’s accessible, start planning a time and date to stop/start the EC2 instance to reduce any impacts.
For each EC2 instance scheduled for retirement, you will need to stop and restart it before the retirement date. That action moves the instance over to a more stable host.
Here is some useful context to keep in mind before stopping your EC2 instance:
If you are using an EBS-backed retiring EC2 instance, be aware that the host is already in a state that prohibits you from launching EC2 instances on that hardware. There’s no need to take further action after stopping and restarting the instance. AWS persists any information stored in EBS volumes, so you don’t need to worry about data loss.
An EBS-backed instance can end up stuck in a stopped stage. If that happens, try forcing the instance to stop through the AWS console or by using the AWS CLI, which can take up to 10 minutes to complete.
If you have data stored on an instance store volume, that won’t persist once you stop your instance. You can prevent data loss by first connecting to the EC2 instance scheduled for retirement via a Remote Desktop Protocol. Next, move the data kept on your instance store volume over to another attached EBS volume.
This quick check for upcoming EC2 retirements can ensure you don’t encounter unexpected changes, but you might not remember to run it regularly.
With Blink, you can find all retiring EC2 instances using an automation like this one:
This automation is available in the Blink library. When it runs, it does the following steps:
This simple automation is easy to customize. Run it on a schedule or send the report via Slack or Teams.
There are over 5K automations in the Blink library to choose from, or you can build your own to match your unique needs.
Get started with Blink today and see how easy automation can be.
Blink is secure, decentralized, and cloud-native. Get modern cloud and security operations today.