If a request times out or an internal server error occurs when you call Auto Scaling API, your client may retry the request. We recommend that you specify the ClientToken parameter in your request to prevent repetition issues caused by retries.
What is idempotence
Idempotence is a property of some operations or resources in mathematics and computer science. It means that an operation or resource leads to the same result, regardless of how many requests are sent. Idempotence plays an important role in the distributed system design.
How do I ensure the idempotence?
Typically, a client retries a request in the following cases: error code 500 (InternalError
) or 503 (ServiceUnavailable
) is reported; no response is returned. When you call Auto Scaling API, you can use your client to generate a token that contains only ASCII characters and does not exceed 64 characters in length and specify the token as the value of the ClientToken parameter to ensure the idempotence of your request.
ClientToken details
A client token is a case-sensitive string that contains only ASCII characters and does not exceed 64 characters in length. You can use a client to generate a client token and must make sure that the client token is unique among different requests. Example:
ClientToken=123e4567-e89b-12d3-a456-426655440000
.If you specified a value for the ClientToken parameter and other request parameters change, Auto Scaling returns the
IdempotentParameterMismatch
error code.NoteYou must specify different values for the SignatureNonce, Timestamp, and Signature parameters in each retry. The reason is that Auto Scaling uses the SignatureNonce parameter to prevent replay attacks and uses the Timestamp parameter to mark the timestamp of each request. Therefore, you must specify different SignatureNonce and Timestamp values in a reinitiated request. Consequently, this changes the value of the Signature parameter.
After you specify the ClientToken parameter in a request, the following results may be returned:
If the HTTP status code 200 is returned, the client receives the same result as the last request after the request is retried. This does not affect your server status.
If an HTTP status code 4xx is returned without the
try it later
error message, a retry will fail. You must troubleshoot issues based on the returned error message before you retry a request.
Sample idempotent requests
The following code provides an example on how to call the CreateScalingGroup API operation to create a scaling group. If you initiate multiple requests that use the same values for the ClientToken parameter and other request parameters, the server returns the same response for each request, and only one scaling group is created.
http(s)://ess.aliyuncs.com/?Action=CreateScalingGroup
&ScalingGroupName=scalinggroup****
&InstanceId=i-28wt4****
&RegionId=cn-qingdao
&MinSize=2
&MaxSize=20
&DefaultCooldown=300
.......
&ClientToken=123e4567-e89b-12d3-a456-42665544****
&<Common request parameters>
API operations
The following API operations in Auto Scaling support the ClientToken parameter. For more API operations that support the ClientToken parameter, see API references.
CreateScalingGroup: Creates a scaling group.
CreateScalingConfiguration: Creates a scaling configuration of the Elastic Compute Service (ECS) type.
RemoveInstances: Removes ECS instances from a scaling group.
ExecuteScalingRule: Executes a scaling rule.
AttachDBInstances: Associates ApsaraDB RDS instances with a scaling group.
AttachServerGroups: Adds server groups for a scaling group.
AttachLoadBalancers: Associates SLB instances with a scaling group.
AttachAlbServerGroups: Adds ALB server groups for a scaling group.
AttachVServerGroups: Adds vServer groups to an SLB instance.