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

ParameterTypeRequiredExampleDescription
ActionStringYesStopInstance

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

InstanceIdStringYesi-bp67acfmxazb4ph****

The ID of the instance.

ConfirmStopBooleanNotrue

This parameter will be removed in the future and is retained only to ensure compatibility. We recommend that you ignore this parameter.

ForceStopBooleanNofalse

Specifies whether to forcefully stop the instance. Valid values:

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

Default value: false.

StoppedModeStringNoKeepCharging

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.

DryRunBooleanNotrue

Specifies whether to check the validity of the request without actually making the request. Default value: false. 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 code 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.

HibernateBooleanNohide
Note This parameter is currently in invitational preview and unavailable for general users.

Response parameters

ParameterTypeExampleDescription
RequestIdString1C488B66-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 codeError codeError messageDescription
403IncorrectInstanceStatusThe 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.
403InstanceLockedForSecurityThe 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.
403DiskErrorIncorrectDiskStatusThe error message returned because the state of the specified disk is invalid.
403InstanceType.ParameterMismatchThe 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.
403InstanceExpiredOrInArrearsThe 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.
403InvalidInstanceId.NotSupportClassic 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.
403InvalidInstanceId.NotSupportPre pay instance does not support this operation.The error message returned because the operation is not supported by the subscription instance.
403InvalidInstanceId.NotSupportLocal disk instance does not support this operation.The error message returned because the operation is not supported by the instance that uses local disks.
403InvalidInstanceId.NotSupportSpot instance does not support this operation.The error message returned because the operation is not supported by the preemptible instance.
403IncorrectInstanceStatus%sThe error message returned because the operation is not supported while the instance is in the current state.
403InvalidParameter.KMSKeyId.CMKNotEnabledThe CMK needs to be enabled.The error message returned because the customer master key (CMK) specified by the KMSKeyId parameter is not enabled. You can call the DescribeKey operation of KMS to query information about the specified CMK.
403InvalidParameter.KMSKeyId.KMSUnauthorizedECS service have no right to access your KMS.The error message returned because ECS is not authorized to access your KMS resources.
404InvalidInstanceId.NotFoundThe specified InstanceId does not exist.The error message returned because the specified InstanceId parameter is invalid.
500InternalErrorThe request processing has failed due to some unknown error.The error message returned because an internal error has occurred. Try again later.
500InternalErrorThe 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.

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