- Documentation
Elastic Compute Service
Elastic Compute Service
User Guide
Instances
Select instance billing method
Spot instance
Best practices for data recovery when spot instances are reclaimed
Spot instance
Best practices for data recovery when spot instances are reclaimed
Best practices for data recovery when spot instances are reclaimed
Spot instances have an interrupt reclamation mechanism. Before being fully reclaimed, the instance enters a locked state and triggers an interruption event. When you receive an interruption notification for a spot instance, you can follow steps below to create a custom image for the instance. Then you can launch a new spot instance with this image to recover data stored on the instance. Process description
warning
- The platform sends a notification of interrupting a spot instance in advance (1 hour in advance for GPU instances and 5 minutes in advance for non-GPU instances). When the reclaim time is reached, the instance is officially reclaimed. However, the specific time taken for data recovery depends on factors such as the image type of your instance and the file size of system volume. For example, the larger the system volume, the longer the recovery time. Make sure that you assess and verify example codes provided in this document before you use them.
- Practice provided in this topic is for reference only. There is no guarantee that the image can be created and data recovered successfully before your instance is reclaimed. We recommend that you regularly back up data for better user experience.
Procedure
Step 1: Create a spot instance
This document takes calling RunInstances operation to create and automatically start a spot instance as an example. Sample request
The following code is applicable if you want to create a General-purpose g2i spot instance with the billing method of pay-as-you-go PostPaid and the spot strategy of automatic bid SpotAsPriceGo.
Sample response
The return of InstanceIds indicates the spot instance is created successfully.
Step 2: Receive the interruption message of spot instance
Except for notifications, the system also generates corresponding system events for you. This article introduces how to call DescribeSystemEvents operation to view the spot instance's event information. Sample request
Sample response
The response of Scheduled status SpotInstanceInterruption.Delete event indicates that spot instance is about to be interrupted.
Step 3: Create a custom image for the spot instance to be reclaimed
After you receive the instance interruption message, call CreateImage operation to create a custom Image for the current instance. Sample request
Sample response
The return of ImageId indicates that the custom image is created.
After you create the custom image, you can call the DescribeImages operation to view the image status. When the image status becomes available, proceed to the next step. Step 4: Use the custom image to create a new spot instance to recover data.
Call the RunInstances operation to use the custom image obtained in Step 3 to recreate a spot instance. For detailed parameters, refer to Step 1, where: - You need to replace ImageId with the new image ID.
- We recommend that the availability zone of the new instance, ZoneId, remains the same as the original instance.
Last updated: 2026.10.14 17:35:11