AWS provides spare compute capacity with its EC2 Spot Instances. Whether you handle high-performance computing...
workloads, run a stateless web server or transcode video, these instance types could be the most economical way to use compute power.
But, while Spot Instances cost up to 90% less than their On-Demand counterparts, they only run as long as your bid price is above the current Spot Instance price. It's important to prepare for potential AWS Spot Instance termination, especially when you have data on the instances that you don't want to lose. Take these measures to prevent data loss.
Hold on to your data
First, store your Spot Instance data in a database, such as Amazon Relational Database Service or Amazon DynamoDB -- or you can even use Amazon S3. When you store data, you prevent unnecessary losses in the event of AWS Spot Instance termination, and you can simply provision new ones and continue where you left off.
Alternatively, you could opt to preserve the entire disk. By default, AWS deletes all Amazon Elastic Block Store (EBS) volumes when Spot Instances are terminated. To keep your disk, uncheck Delete for EBS volumes when you create a Spot Instance request in AWS Management Console.
Beat the buzzer
AWS also provides Spot Instance interruption notices, which can help prevent data loss. When your bid price becomes lower than the current price, AWS' Spot Instance termination process begins, but it doesn't happen immediately. Instead, AWS sends you a two-minute warning, which gives you time to offload your data and complete other preparations, such as detaching your instances from a load balancer.
There are multiple ways to detect whether your instances are about to terminate. For example, the instance metadata updates with the exact time of the shutdown:
You can also use DescribeSpotInstanceRequests, rather than poll from the instance itself.
Additionally, AWS added Spot Instance interruption notices to Amazon CloudWatch Events in January 2018. This lets you prepare for AWS Spot Instance termination via Lambda or Simple Notification Service topics, which can help automate the data backup process. AWS has also upgraded Spot Instances with other features, like streamlined access to capacity, instance hibernation and an option to purchase without placing a bid, which help make them a worthwhile option for budget-conscious users.
Dig Deeper on Amazon EC2 (Elastic Compute Cloud) management
Related Q&A from Ofir Nachmani
Personnel changes are inevitable at an enterprise, and security teams need to revoke AWS credentials accordingly to ensure the integrity of their ... Continue Reading
To gain a Professional-level AWS certification, AWS requires at least two years of experience with its platform. But will it help your career, or is ... Continue Reading
If you get clumsy with AWS security, you can put your whole business at risk. Be wary of these common errors, and implement best practices to secure ... Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.