All Products
Search
Document Center

Elastic Compute Service:AttachDisk

Last Updated:Mar 19, 2024

Attaches a pay-as-you-go data disk or a system disk to an Elastic Compute Service (ECS) instance. The instance and the disk must reside in the same zone.

Operation description

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

  • The disk that you want to attach must be in the Available state.``

  • When the disk is attached as a data disk, take note of the following items:

    • The instance must be in the Running or Stopped state.````
    • If the disk was separately purchased, the billing method of the disk must be pay-as-you-go.
    • If the disk is a system disk detached from an instance, no limits apply to the billing method of the disk.
  • When the disk is attached as a system disk, take note of the following items:

    • The instance must be the original instance from which the system disk was detached.
    • The instance must be in the Stopped state.``
    • The logon credentials must be configured.
  • If the response contains {"OperationLocks": {"LockReason" : "security"}} when you query the information of the instance, the instance is locked for security reasons and all operations are prohibited on the instance.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

There is currently no authorization information disclosed in the API.

Request parameters

ParameterTypeRequiredDescriptionExample
InstanceIdstringYes

The ID of the instance to which you want to attach the disk.

i-bp1dq5lozx5f4pmd****
DiskIdstringYes

The ID of the disk. The disk specified by the DiskId parameter and the instance specified by the InstanceId parameter must reside in the same zone.

Note For more information about the limits on attaching a data disk and a system disk, see the "Usage notes" section of this topic.
d-bp1j4l5axzdy6ftk****
DevicestringNo

The device name of the disk.

Note This parameter will be removed in the future. We recommend that you use other parameters to ensure compatibility.
testDeviceName
DeleteWithInstancebooleanNo

Specifies whether to release the disk when the instance is released. Valid values:

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

Default value: false.

When you specify this parameter, take note of the following items:

  • If OperationLocks in the DescribeInstances response contains "LockReason" : "security" for the instance to which the disk is attached, the instance is locked for security reasons. Regardless of whether you set DeleteWithInstance to false, the DeleteWithInstance parameter is ignored, and the disk is released when the instance is released.
  • You cannot specify this parameter for disks for which the multi-attach feature is enabled.
false
BootablebooleanNo

Specifies whether to attach the disk as a system disk.

Default value: false.

Note If you set Bootable to true, the instance must be in the No System Disk state.
false
PasswordstringNo

The password that is set when you attach the system disk. The password is applicable only to the administrator and root users. The password must be 8 to 30 characters in length and must contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. The following special characters are supported:

()`~!@#$%^&*-_+=|{}[]:;'<>,.?/

For Windows instances, passwords cannot start with a forward slash (/).

Note If Password is configured, we recommend that you send requests over HTTPS to prevent password leaks.
EcsV587!
KeyPairNamestringNo

The name of the SSH key pair that you bind to the Linux instance when you attach the system disk.

  • Windows instances do not support logons based on SSH key pairs. The Password parameter takes effect even if the KeyPairName parameter is specified.
  • For Linux instances, the username and password-based logon method is disabled by default.
KeyPairTestName

Response parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

Examples

Sample success responses

JSONformat

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

Error codes

HTTP status codeError codeError messageDescription
400InvalidDevice.MalformedThe specified device is not valid.The specified disk device name does not exist.
400IncorrectInstanceStatusThe current status of the resource does not support this operation.The resource is in a state that does not support the current operation.
400InvalidParameterThe input parameter is mandatory for processing this request is empty.A required parameter is not specified.
400InvalidRegionId.MalFormedThe specified RegionId is not valid.The specified region does not exist.
400InvalidOperation.InstanceTypeNotSupportThe instance type of the specified instance does not support hot attach disk.The instance to which the disk is attached does not support the hot swapping of disks.
400DiskCategory.OperationNotSupportedThe operation is not supported to the specified disk due to its disk category.The specified disk category does not support this operation.
400InvalidOperation.InstanceTypeNotSupportThe specified disk which has kms key should only attach to ioOptimized instance.The specified instance is invalid. You can set Key Management Service (KMS) keys only for I/O optimized instances.
400InvalidDisk.DiskNotBootableThe specified disk is not a bootable disk, can not be attached as system disk.-
400InvalidInstance.NotOriginInstanceThe specified disk can not attached to other instance as system disk.-
400InvalidParameter.AllEmpty%sThe required parameters are not specified.
403InstanceDiskLimitExceededThe amount of the disk on instance in question reach its limits.The specified instance has reached the maximum number of disks that can be attached to it.
403InvalidDevice.InUseThe specified device has been occupied.The specified device has been occupied.
403IncorrectDiskStatus%s-
403DiskNotPortableThe specified disk is not a portable disk.The specified disk is not removable.
403InstanceLockedForSecurityThe instance is locked due to security.The operation is not supported while the instance is locked for security reasons.
403ResourcesNotInSameZoneThe specified instance and disk are not in the same zone.The specified instance and disk are not in the same zone.
403InstanceExpiredOrInArrearsThe specified operation is denied as your prepay instance is expired (prepay mode) or in arrears (afterpay mode).The subscription instance has expired. You must renew the instance before you can proceed.
403DiskInArrearsThe specified operation is denied as your disk owing fee.Your account has overdue payments for the specified disk.
403DiskErrorIncorrectDiskStatus.The disk state is invalid.
403DiskId.ValueNotSupportedThe specified parameter diskid is not supported.The specified EBS device category does not support the operation.
403DiskId.StatusNotSupportedThe specified disk status is not supported.The disk is in a state that does not support the current operation.
403IncorrectInstanceStatus.NotSupportESSDThe operation is not supported in this status, please reboot the instance.-
403IncorrectDiskStatusThe operation is not supported in this status.The disk is in a state that does not support the current operation. Make sure that the disk is available and that your account has no overdue payments.
403UserNotInTheWhiteListThe user is not in disk white list.You are not authorized to manage the disk. Try again when you are authorized.
403InvalidParameter.KMSKeyId.CMKNotEnabledThe CMK needs to be enabled.The customer master key (CMK) is not enabled when KMSKeyId is specified for an encrypted disk. You can call the DescribeKey operation of KMS to query information about the specified CMK.
403InvalidParameter.KMSKeyId.CMKUnauthorizedThe CMK needs to be added ECS tag.-
403InvalidParameter.KMSKeyId.KMSUnauthorizedECS service have no right to access your KMS.ECS is not authorized to access your KMS resources.
403DependencyViolation.WindowsInstanceThe instance image is windows, cannot use ssh key pair to login.-
403InvalidInstanceType.NotSupportDiskCategoryThe instanceType of the specified instance does not support this disk category.The instance type does not support the current disk category. Try another instance type. For information about the disk categories supported by instance types, see the instance family documentation.
403InvalidInstanceType.NotSupportPL0The instanceType of the specified instance does not support PL0 of cloud_essd.-
403InvalidInstanceType.NvmeRequiredThe instanceType of the specified instance requires nvme protocol.The instance type of the specified instance requires the NVMe protocol.
403InvalidInstanceType.NvmeUnsupportedThe instanceType of the specified instance does not support nvme protocol.The instance type of the specified instance does not support the NVMe protocol.
403InvalidInstanceType.NotSupportMultiAttachDiskThe instanceType of the specified instance does not support multi attach disk.Disks for which the multi-attach feature is enabled cannot be attached to instances of the specified instance type.
403DiskAttachedNumberExceededThe attaching times of the specified disk exceeded.The specified disk has reached the maximum number of instances to which it can be attached.
403InvalidOperation.CanNotAttachMultiAttachDiskAsSystemDiskMulti attach disk can not be attached as system disk.Disks for which the multi-attach feature is enabled cannot be attached as system disks.
403DeleteWithInstance.ConflictMulti attach disk cannot be set to DeleteWithInstance attribute.Disks for which the multi-attach feature is enabled do not support the DeleteWithInstance attribute.
404InvalidInstanceId.NotFoundThe specified InstanceId does not exist.The specified instance does not exist.
404InvalidDiskId.NotFoundThe specified disk does not exist.The specified disk does not exist. Check whether the disk ID is correct.
404InvalidDisk.InUseThe specified disk has been occupied.The specified disk is already in use.
500InternalErrorThe request processing has failed due to some unknown error.An internal error has occurred. Try again later.
500InternalErrorThe request processing has failed due to some unknown error, exception or failure.An internal error has occurred. Try again later.

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2023-11-24The Error code has changedsee changesets
Change itemChange content
Error CodesThe Error code has changed.
    Error Codes 403 change
    delete Error Codes: 400
    delete Error Codes: 404
    delete Error Codes: 500