You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
Spot instance
Best practices for data recovery when spot instances are reclaimed
Copy page
Download PDF
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.​
tip​
After a spot instance is released, refer to Status of instance resources after an ECS instance is deleted for details on retained data.​
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.​
tip​
You can also refer to Purchasing spot instances and create a spot instance in the ECS console.​
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.​
​
GET /?Action=RunInstances&Version=2020-04-01&ZoneId=cn-beijing-a&ImageId=image3tgt71djf14bwbh7****&InstanceTypeId=ecs.g2i.xlarge&InstanceName=instance-test&InstanceChargeType=PostPaid&SpotStrategy=SpotAsPriceGo&Count=1&Password=password@123&NetworkInterfaces.1.SubnetId=subnet-3thbjdy3rh4bwbh8****&NetworkInterfaces.1.SecurityGroupIds.1=sg3thbinrkp94bwbha****&Volumes.1.VolumeType=PTSSD&Volumes.1.Size=40 HTTP/1.1​
Host: open.volcengineapi.com​
Region: cn-beijing​
Service: ecs​
​
Sample response​
The return of InstanceIds indicates the spot instance is created successfully.​
​
"Result": {​
"InstanceIds": [​
"i-3tigy72q3u3vj0******"​
]​
}​
​
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.​
tip​
You can also refer to Configuring event monitoring notifications to subscribe to the "spot instance interruption, instance release" event message notifications through the ECS console.​
Sample request​
​
GET /?Action=DescribeSystemEvents&Version=2020-04-01&ResourceIds.1=i-3tigy72q3u3vj0****** HTTP/1.1​
Host: open.volcengineapi.com​
Region: cn-beijing​
ServiceName: ecs​
​
Sample response​
The response of Scheduled status SpotInstanceInterruption.Delete event indicates that spot instance is about to be interrupted.​
​
"Result": {​
"SystemEvents": [​
{​
"Id": "t-3ti9101aju3vj0******",​
"CreatedAt": "2022-06-15T16:34:34+08:00",​
"UpdatedAt": "2022-06-15T16:34:49+08:00",​
"ResourceId": "i-3tigy72q3u3vj0******",​
"Type": "SpotInstanceInterruption.Delete",​
"Status": "Scheduled",​
"OperatedEndAt":"2021-07-10T18:11:46+08:00"​
}​
],​
"NextToken": "bHpwdXJja2RxemU1eG5sb3NzdGcW1-RCEq******"​
}​
​
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.​
tip​
You can also refer to Creating custom images from a Linux instance to create a custom image in the ECS console.​
Sample request​
​
GET /?Action=CreateImage&Version=2020-04-01&InstanceId=i-3tigy72q3u3vj0******&ImageName=image-1 HTTP/1.1​
Host: open.volcengineapi.com​
Region: cn-beijing​
ServiceName: ecs​
​
Sample response​
The return of ImageId indicates that the custom image is created.​
​
{​
"Result": {​
"ImageId": "image-3teco18f1w5a71******"​
}​
}​
​
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.​
​
GET /?Action=DescribeImages&Version=2020-04-01&ImageIds.1=image-3teco18f1w5a71****** HTTP/1.1​
Host: open.volcengineapi.com​
Region: cn-beijing​
Service: ecs​
​
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.​
tip​
You can also refer to Purchasing spot instances and recreate a spot instance in the ECS console.​
​
Last updated: 2026.10.14 17:35:11