Detaches a pay-as-you-go data disk or a system disk from an Elastic Compute Service (ECS) instance.

Description

When you call this operation, take note of the following limits:

  • The disk must be attached to an ECS instance and in the In Use (In_Use) state.
  • The instance from which you want to detach the data disk must be in the Running (Running) or Stopped (Stopped) state.
  • The instance from which you want to detach the system disk must be in the Stopped (Stopped) state.
  • If OperationLocks in the response contains "LockReason" : "security" when you query information of an instance, the instance is locked for security reasons and all operations cannot take effect on the instance.
  • DetachDisk is an asynchronous operation. It takes about 1 minute for a disk to be detached from an instance after the operation is called.

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 DetachDisk

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

DiskId String Yes d-bp67acfmxazb4p****

The ID of the disk to be detached.

InstanceId String Yes i-bp67acfmxazb4p****

The ID of the ECS instance from which the disk is to be detached.

DeleteWithInstance Boolean No false

Specifies whether to automatically release the system disk when the instance from which the system disk is to be detached is released. Valid values:

  • true: The system disk is released when the instance is released.
  • false: The system disk is not released when the instance is released. The system disk is retained as a pay-as-you-go data disk.

Default value: true.

Take note of the following items:

  • This parameter cannot be set for disks for which the multi-attach feature is enabled.
  • If a data disk is to be detached, the default value is false.

Response parameters

Parameter Type Example Description
RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

The ID of the request.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=DetachDisk
&DiskId=d-bp67acfmxazb4p****
&InstanceId=i-bp67acfmxazb4p****
&<Common request parameters>

Sample success responses

XML format

<DetachDiskResponse>
      <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E</RequestId>
</DetachDiskResponse>

JSON format

{
    "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

Error codes

HTTP status code Error code Error message Description
400 InvalidParameter The input parameter is mandatory for processing this request is empty. The error message returned because a required parameter is not set.
400 InvalidRegionId.MalFormed The specified RegionId is not valid The error message returned because the specified RegionId parameter is invalid.
400 InvalidOperation.InstanceTypeNotSupport The instance type of the specified instance does not support hot detach disk. The error message returned because the instance to which the disk is attached does not support the hot swapping of disks.
403 IncorrectDiskStatus The current disk status does not support this operation. The error message returned because the operation is not supported while the disk is in the current state. Make sure that the disk is usable and you have no overdue payments for it.
403 DiskNotPortable The specified disk is not a portable disk. The error message returned because the specified disk is not removable.
403 InstanceLockedForSecurity The instance is locked due to security. The error message returned because the operation is not supported while the instance is locked for security reasons.
403 DependencyViolation The specified disk has not been attached on the specified instance. The error message returned because the operation is not supported while the resource has other dependencies. For example, the specified disk is not attached to the specified instance, or the specified security group cannot be deleted while it contains instances. Remove the dependencies and try again.
403 DiskTypeViolation The specified disk is a system disk and cannot support the operation. The error message returned because the specified disk is the system disk and cannot be detached from the instance to which it is attached.
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 UserNotInTheWhiteList The user is not in disk white list. The error message returned because you are not authorized to manage the disk. Try again when you are authorized.
403 InvalidInstance.ImageCategory The image category of the specified instance does not support detaching system disk. The error message returned because the specified system disk cannot be detached from the specified instance while the image of the instance is in the current state. Possible cause: The image used to create the instance was deleted.
403 DeleteWithInstance.Conflict Multi attach disk cannot be set to DeleteWithInstance attribute. The error message returned because the DeleteWithInstance attribute is invalid for disks for which the multi-attach feature is enabled.
404 InvalidInstanceId.NotFound The specified InstanceId does not exist. The error message returned because the specified InstanceId parameter is invalid.
404 InvalidDiskId.NotFound The specified disk does not exist. The error message returned because the specified disk does not exist. Check whether the disk ID is correct.
404 InvalidDisk.AlreadyDetached The specified disk has been detached. The error message returned because the specified disk has been detached from the instance.
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.