AttachVolume
Attaches an Amazon EBS volume to a running or stopped
instance, and exposes it to the instance with the specified device name.
The maximum number of Amazon EBS volumes that you can attach to an instance depends on the
instance type. If you exceed the volume attachment limit for an instance type, the attachment
request fails with the AttachmentLimitExceeded error. For more information,
see Instance
volume limits.
After you attach an EBS volume, you must make it available for use. For more information, see Make an EBS volume available for use.
If a volume has an AWS Marketplace product code:
-
The volume can be attached only to a stopped instance.
-
AWS Marketplace product codes are copied from the volume to the instance.
-
You must be subscribed to the product.
-
The instance type and operating system of the instance must support the product. For example, you can't detach a volume from a Windows instance and attach it to a Linux instance.
For more information, see Attach an Amazon EBS volume to an instance in the Amazon EBS User Guide.
Request Parameters
The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.
- Device
-
The device name (for example,
/dev/sdhorxvdh).Type: String
Required: Yes
- DryRun
-
Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is
DryRunOperation. Otherwise, it isUnauthorizedOperation.Type: Boolean
Required: No
- EbsCardIndex
-
The index of the EBS card. Some instance types support multiple EBS cards. The default EBS card index is 0.
Type: Integer
Required: No
- InstanceId
-
The ID of the instance.
Type: String
Required: Yes
- VolumeId
-
The ID of the EBS volume. The volume and instance must be within the same Availability Zone.
Type: String
Required: Yes
Response Elements
The following elements are returned by the service.
- associatedResource
-
The ARN of the AWS-managed resource to which the volume is attached.
Type: String
- attachTime
-
The time stamp when the attachment initiated.
Type: Timestamp
- availabilityZone
-
The name of the Availability Zone of the attachment. For a Multi-Availability Zone volume, compare this value with the volume's
AvailabilityZone(the active Availability Zone) and the standby Availability Zone in itsMultiAvailabilityZoneConfigurationto determine whether the instance is in the active or the standby Availability Zone.Type: String
- availabilityZoneId
-
The ID of the Availability Zone of the attachment. For a Multi-Availability Zone volume, compare this value with the volume's
AvailabilityZoneId(the active Availability Zone) and the standby Availability Zone ID in itsMultiAvailabilityZoneConfigurationto determine whether the instance is in the active or the standby Availability Zone.Type: String
- deleteOnTermination
-
Indicates whether the EBS volume is deleted on instance termination.
Type: Boolean
- device
-
The device name.
If the volume is attached to an AWS-managed resource, this parameter returns
null.Type: String
- ebsCardIndex
-
The index of the EBS card. Some instance types support multiple EBS cards. The default EBS card index is 0.
Type: Integer
- instanceId
-
The ID of the instance.
If the volume is attached to an AWS-managed resource, this parameter returns
null.Type: String
- instanceOwningService
-
The service principal of the AWS service that owns the underlying resource to which the volume is attached.
This parameter is returned only for volumes that are attached to AWS-managed resources.
Type: String
- requestId
-
The ID of the request.
Type: String
- status
-
The attachment state of the volume.
Type: String
Valid Values:
attaching | attached | detaching | detached | busy - trimState
-
A read-only value that indicates whether the volume is reporting TRIM support to the operating system for this attachment. Amazon EBS sets this value from the volume's
TrimOnAttachsetting when the volume attaches, and the value doesn't change for the life of the attachment. You can't setTrimStatedirectly. To change it, modifyTrimOnAttach, then detach and reattach the volume. For volumes with Multi-Attach enabled, each attachment has its ownTrimState. This value isn't returned for unattached volumes.Valid values:
-
enabled: The volume reports TRIM support to the operating system. -
disabled: The volume does not report TRIM support to the operating system.
Type: String
Valid Values:
enabled | disabled -
- volumeId
-
The ID of the volume.
Type: String
Errors
For information about the errors that are common to all actions, see Common Error Types.
Examples
Example 1
This example request attaches the volume with the ID
vol-1234567890abcdef0 to the instance with the ID
i-1234567890abcdef0 and exposes it as /dev/sdh.
Sample Request
https://ec2.amazonaws.com/?Action=AttachVolume
&VolumeId=vol-1234567890abcdef0
&InstanceId=i-1234567890abcdef0
&Device=/dev/sdh
&AUTHPARAMS
Sample Response
<AttachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<volumeId>vol-1234567890abcdef0</volumeId>
<instanceId>i-1234567890abcdef0</instanceId>
<device>/dev/sdh</device>
<status>attaching</status>
<attachTime>YYYY-MM-DDTHH:MM:SS.000Z</attachTime>
</AttachVolumeResponse>
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: