Instance / Action / attach_volume
attach_volume¶
- EC2.Instance.attach_volume(**kwargs)¶
Attaches an Amazon EBS volume to a
runningorstoppedinstance, and exposes it to the instance with the specified device name.Note
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
AttachmentLimitExceedederror. 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 Amazon Web Services Marketplace product code:
The volume can be attached only to a stopped instance.
Amazon Web Services 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.
See also: AWS API Documentation
Request Syntax
response = instance.attach_volume( Device='string', VolumeId='string', EbsCardIndex=123, DryRun=True|False )
- Parameters:
Device (string) –
[REQUIRED]
The device name (for example,
/dev/sdhorxvdh).VolumeId (string) –
[REQUIRED]
The ID of the EBS volume. The volume and instance must be within the same Availability Zone.
EbsCardIndex (integer) – The index of the EBS card. Some instance types support multiple EBS cards. The default EBS card index is 0.
DryRun (boolean) – 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.
- Return type:
dict
- Returns:
Response Syntax
{ 'DeleteOnTermination': True|False, 'AssociatedResource': 'string', 'InstanceOwningService': 'string', 'EbsCardIndex': 123, 'AvailabilityZone': 'string', 'AvailabilityZoneId': 'string', 'TrimState': 'enabled'|'disabled', 'VolumeId': 'string', 'InstanceId': 'string', 'Device': 'string', 'State': 'attaching'|'attached'|'detaching'|'detached'|'busy', 'AttachTime': datetime(2015, 1, 1) }
Response Structure
(dict) –
Describes volume attachment details.
DeleteOnTermination (boolean) –
Indicates whether the EBS volume is deleted on instance termination.
AssociatedResource (string) –
The ARN of the Amazon Web Services-managed resource to which the volume is attached.
InstanceOwningService (string) –
The service principal of the Amazon Web Services service that owns the underlying resource to which the volume is attached.
This parameter is returned only for volumes that are attached to Amazon Web Services-managed resources.
EbsCardIndex (integer) –
The index of the EBS card. Some instance types support multiple EBS cards. The default EBS card index is 0.
AvailabilityZone (string) –
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.AvailabilityZoneId (string) –
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.TrimState (string) –
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.
VolumeId (string) –
The ID of the volume.
InstanceId (string) –
The ID of the instance.
If the volume is attached to an Amazon Web Services-managed resource, this parameter returns
null.Device (string) –
The device name.
If the volume is attached to an Amazon Web Services-managed resource, this parameter returns
null.State (string) –
The attachment state of the volume.
AttachTime (datetime) –
The time stamp when the attachment initiated.