Lab6b : Attach a volume to multiple instances with Amazon EBS Multi-Attach
Amazon EBS Multi-Attach enables you to attach a single Provisioned IOPS SSD (io1
or io2
) volume to multiple instances that are in the same Availability Zone.
You can attach multiple Multi-Attach enabled volumes to an instance or set of instances. Each instance to which the volume is attached has full read and write permission to the shared volume. Multi-Attach makes it easier for you to achieve higher application availability in applications that manage concurrent write operations.
Multi-Attach enabled volumes can be managed in much the same way that you would manage any other Amazon EBS volume. However, in order to use the Multi-Attach functionality, you must enable it for the volume. When you create a new volume, Multi-Attach is disabled by default.
Enable Multi-Attach
You can enable Multi-Attach during volume creation. Use one of the following methods.
To enable Multi-Attach during volume creation
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- In the navigation pane, choose Volumes.
- Choose Create volume.
- For Volume type, choose Provisioned IOPS SSD (
io1
) or Provisioned IOPS SSD (io2
). - For Size and IOPS, choose the required volume size and the number of IOPS to provision.
- For Availability Zone, choose the same Availability Zone that the instances are in.
- For Amazon EBS Multi-Attach, choose Enable Multi-Attach.
- (Optional) For Snapshot ID, choose the snapshot from which to create the volume.
- Set the encryption status for the volume.If the selected snapshot is encrypted, or if your account is enabled for encryption by default, then encryption is automatically enabled and you can’t disable it. You can choose the KMS key to use to encrypt the volume.If the selected snapshot is unencrypted and your account is not enabled for encryption by default, encryption is optional. To encrypt the volume, for Encryption, choose Encrypt this volume and then select the KMS key to use to encrypt the volume.
Note
You can attach encrypted volumes only to instances that support Amazon EBS encryption. For more information, see Amazon EBS encryption.
- (Optional) To assign custom tags to the volume, in the Tags section, choose Add tag, and then enter a tag key and value pair. .
- Choose Create volume.
You can also enable Multi-Attach for io2
volumes after creation, but only if they are not attached to any instances.
Note
You can’t enable Multi-Attach for io1
volumes after creation.
Use one of the following methods to enable Multi-Attach for an io2
volume after creation.
To enable Multi-Attach after creation
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- In the navigation pane, choose Volumes.
- Select the volume and choose Actions, Modify volume.
- For Amazon EBS Multi-Attach, choose Enable Multi-Attach.
- Choose Modify.
Disable Multi-Attach
You can disable Multi-Attach for an io2
volume only if it is attached to no more than one instance.
Note
You can’t disable Multi-Attach for io1
volumes after creation.
Use one of the following methods to disable Multi-Attach for an io2
volume.
To disable Multi-Attach after creation
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- In the navigation pane, choose Volumes.
- Select the volume and choose Actions, Modify volume.
- For Amazon EBS Multi-Attach, clear Enable Multi-Attach.
- Choose Modify.
Attach a volume to instances
You attach a Multi-Attach enabled volume to an instance in the same way that you attach any other EBS volume. For more information, see Attach an Amazon EBS volume to an instance.
Delete on termination
Multi-Attach enabled volumes are deleted on instance termination if the last attached instance is terminated and if that instance is configured to delete the volume on termination. If the volume is attached to multiple instances that have different delete on termination settings in their volume block device mappings, the last attached instance’s block device mapping setting determines the delete on termination behavior.
To ensure predictable delete on termination behavior, enable or disable delete on termination for all of the instances to which the volume is attached.
By default, when a volume is attached to an instance, the delete on termination setting for the block device mapping is set to false. If you want to turn on delete on termination for a Multi-Attach enabled volume, modify the block device mapping.
If you want the volume to be deleted when the attached instances are terminated, enable delete on termination in the block device mapping for all of the attached instances. If you want to retain the volume after the attached instances have been terminated, disable delete on termination in the block device mapping for all of the attached instances. For more information, see Preserve data when an instance is terminated.
You can modify an instance’s delete on termination setting at launch or after it has launched. If you enable or disable delete on termination during instance launch, the settings apply only to volumes that are attached at launch. If you attach a volume to an instance after launch, you must explicitly set the delete on termination behavior for that volume.
You can modify an instance’s delete on termination setting using the command line tools only.
To modify the delete on termination setting for an existing instance
Use the modify-instance-attribute command and specify the DeleteOnTermination
attribute in the --block-device-mappings option
.
aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0
--block-device-mappings file://mapping.json
Specify the following in mapping.json
.
[
{
"DeviceName": "/dev/sdf
", "Ebs": { "DeleteOnTermination": true|false
} } ]
Monitor a Multi-Attach enabled volume
Data is aggregated across all of the attached instances. You can’t monitor metrics for individual attached instances.