Stops an Elastic Compute Service (ECS) instance in the Running state. After the operation is called, the state of the instance changes to Stopping and then to Stopped.

Description

  • If you call the DescribeInstances operation to query the details of an instance and OperationLocks in the response contains "LockReason": "security", the instance is locked for security reasons and cannot be stopped. For more information, see API behavior when an instance is locked for security reasons.
  • If economical mode is enabled, you can set StoppedMode to KeepCharging to enable standard mode. Then, after your instance is stopped in standard mode, you continue to be charged for it, and its instance type resources and public IP address are retained.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes StopInstance

The operation that you want to perform. Set the value to StopInstance.

InstanceId String Yes i-bp67acfmxazb4ph****

The ID of the instance.

ConfirmStop Boolean No true
Note This parameter will be removed in the future and is retained only to ensure compatibility. We recommend that you ignore this parameter.
ForceStop Boolean No false

Specifies whether to forcibly stop the instance. Valid values:

  • true: forcibly stops the instance.
  • false: normally stops the instance.

Default value: false.

StoppedMode String No KeepCharging

The stop mode of the pay-as-you-go instance. Valid values:

  • StopCharging: economical mode. For information about how StopCharging takes effect, see the "Prerequisites" section in Economical mode.
  • KeepCharging: standard mode. After the instance is stopped in standard mode, you continue to be charged for it.

Default value: If the prerequisites required for enabling economical mode are met and you have enabled this mode in the ECS console, the default value is StopCharging. For more information, see the "Enable economical mode" section in Economical mode. Otherwise, the default value is KeepCharging.

DryRun Boolean No true

Specifies whether to check the validity of the request without actually making the request. Valid values:

  • true: The validity of the request is checked, but the request is not made. Check items include the required parameters, service limits, available ECS resources, and the request format. If the check fails, the corresponding error message is returned. If the check succeeds, the DryRunOperation error code is returned.
  • false: The validity of the request is checked, and the request is made if the check succeeds.

Default value: false.

Response parameters

Parameter Type Example Description
RequestId String 1C488B66-B819-4D14-8711-C4EAAA13AC01

The ID of the request.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=StopInstance
&InstanceId=i-bp67acfmxazb4ph****
&ForceStop=false
&StoppedMode=KeepCharging
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<StopInstanceResponse>
    <RequestId>1C488B66-B819-4D14-8711-C4EAAA13AC01</RequestId>
</StopInstanceResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "1C488B66-B819-4D14-8711-C4EAAA13AC01"
}

Error codes

Http status code Error code Error message Description
403 IncorrectInstanceStatus The current status of the resource does not support this operation. The error message returned because the operation is not supported while the resource is in the current state.
403 InstanceLockedForSecurity The specified operation is denied as your instance is locked for security reasons. The error message returned because the operation is not supported while the instance is locked for security reasons.
403 DiskError IncorrectDiskStatus The error message returned because the state of the specified disk is invalid.
403 InstanceType.ParameterMismatch The input parameter ConfirmStop must be true when an instance have localstorage. The error message returned because the ConfirmStop parameter is set to false for the instance that uses local storage.
403 InstanceExpiredOrInArrears The specified operation is denied as your prepay instance is expired (prepay mode) or in arrears (afterpay mode). The error message returned because the subscription instance has expired. Renew the instance and try later.
403 InvalidInstanceId.NotSupport Classic network Instance does not support this operation. The error message returned because the operation is not supported by the instance located in the classic network.
403 InvalidInstanceId.NotSupport Pre pay instance does not support this operation. The error message returned because the operation is not supported by the subscription instance.
403 InvalidInstanceId.NotSupport Local disk instance does not support this operation. The error message returned because the operation is not supported by the instance that uses local disks.
403 InvalidInstanceId.NotSupport Spot instance does not support this operation. The error message returned because the operation is not supported by the preemptible instance.
403 IncorrectInstanceStatus %s The error message returned because the operation is not supported while the instance is in the current state.
403 InvalidParameter.KMSKeyId.CMKNotEnabled The CMK needs to be enabled. The error message returned because the customer master key (CMK) is not enabled when a Key Management Service (KMS) key ID is specified for a disk. You can call the DescribeKey operation of KMS to query information about the specified CMK.
403 InvalidParameter.KMSKeyId.KMSUnauthorized ECS service have no right to access your KMS. The error message returned because ECS is not authorized to access your KMS resources.
404 InvalidInstanceId.NotFound The specified InstanceId does not exist. The error message returned because the specified InstanceId parameter is invalid.
500 InternalError The request processing has failed due to some unknown error. The error message returned because an internal error has occurred. Try again later. If the error persists, submit a ticket.
500 InternalError The request processing has failed due to some unknown error, exception or failure. The error message returned because an internal error has occurred. Try again later. If the error persists, submit a ticket.

For a list of error codes, visit the API Error Center.