Using Amazon Elastic Block Store
Topics
- Amazon EBS API Overview
- How to Create an Amazon EBS Volume
- How to Attach the Volume to an Instance
- How to Describe Volumes and Instances
- How to Make an Amazon EBS Volume Available for Use
- How to Create an Amazon EBS Snapshot
- How to Describe Snapshots
- How to Detach an Amazon EBS Volume from an Instance
- How to Delete an Amazon EBS Snapshot
- How to Delete an Amazon EBS Volume
- Related Topics
This section provides examples of how to create and use Amazon Elastic Block Store (Amazon EBS) volumes.
Amazon EBS API Overview
To configure and use Amazon EBS, we provide eight API functions. This section provides a brief overview of each function. For information on Amazon EBS concepts, see Amazon Elastic Block Store.
-
CreateVolume—Creates a new Amazon EBS volume using the specified size or creates a new volume based on a previously created snapshot.
-
DeleteVolume—Deletes the specified volume.
This function does not delete any snapshots that were created from this volume.
-
DescribeVolumes—Describes all volumes, including size, source snapshot, Availability Zone, creation time, and status (
available
,in-use
). -
AttachVolume—Attaches the specified volume to a specified instance, exposing the volume using the specified device name.
A volume can only be attached to a single instance at any time. The volume and instance must be in the same Availability Zone and the instance must be running.
-
DetachVolume—Detaches the specified volume from the instance to which it is attached.
This operation does not delete the volume. The volume can be attached to another instance and will have the same data as when it was detached.
-
CreateSnapshot—Creates a snapshot of the volume you specify.
Once created, you can use the snapshot to create volumes that contain exactly the same data as the original volume.
-
DeleteSnapshot—Deletes the specified snapshot.
This function does not affect currently running Amazon EBS volumes, regardless of whether they were used to create the snapshot or were derived from the snapshot.
-
DescribeSnapshots—Describes all snapshots, including their source volume, snapshot initiation time, progress (percentage complete), and status (
pending
,completed
).
How to Create an Amazon EBS Volume
To use Amazon EBS, you first create a volume that can be attached to any Amazon EC2 instance within the same Availability Zone. This example creates an 800 GiB Amazon EBS volume.
Procedure
To create an Amazon EBS volume
-
If you are using SOAP, construct the following request:
<CreateVolume xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <size>
size
</size> <availabilityZone>zone
</availabilityZone> </CreateVolume> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=CreateVolume &Size=
size
&AvailabilityZone=zone
&...auth parameters... -
View output similar to the following:
<CreateVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <volumeId>vol-4d826724</volumeId> <size>800</size> <status>creating</status> <createTime>2008-05-07T11:51:50.000Z</createTime> <availabilityZone>us-east-1a</availabilityZone> <snapshotId></snapshotId> </CreateVolumeResponse>
How to Attach the Volume to an Instance
This section describes how to attach a volume that you created to an instance.
Note | |
---|---|
Windows instances currently support devices xvda through xvdp. Devices xvda and xvdb are reserved by the operating system, xvdc is assigned to drive C:\, and, depending on the instance type, devices xvdd through xvde might be reserved by the instance stores. Any device that is not reserved can be attached to an Amazon EBS volume. For a list of devices that are reserved by the instance stores, see Instance Storage. |
Procedure
To attach an Amazon EBS volume
-
If you are using SOAP, construct the following request:
<AttachVolume xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <volumeId>
volume-id
</volumeId> <instanceId>instance-id
</instanceId> <device>device
</device> </AttachVolume> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=AttachVolume &VolumeId=
volume-id
&InstanceId=instance-id
&Device=device
&...auth parameters... -
View output similar to the following:
<AttachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <volumeId>vol-4d826724</volumeId> <instanceId>i-6058a509</instanceId> <device>/dev/sdh</device> <status>attaching</status> <attachTime>2008-05-07T11:51:50.000Z</attachTime> </AttachVolumeResponse>
How to Describe Volumes and Instances
After creating Amazon EBS volumes and attaching them to instances, you should verify they are available.
Procedure
To view information about an Amazon EBS volume
-
If you are using SOAP, construct the following request:
<DescribeVolumes xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> </DescribeVolumes>
-
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=DescribeVolumes &...auth parameters...
-
View output similar to the following:
<DescribeVolumesResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <volumeSet> <item> <volumeId>vol-4282672b</volumeId> <size>800</size> <status>in-use</status> <createTime>2008-05-07T11:51:50.000Z</createTime> <attachmentSet> <item> <volumeId>vol-4282672b</volumeId> <instanceId>i-6058a509</instanceId> <size>800</size> <snapshotId>snap-12345678</snapshotId> <availabilityZone>us-east-1a</availabilityZone> <status>attached</status> <attachTime>2008-05-07T12:51:50.000Z</attachTime> </item> </attachmentSet> </item> </volumeSet>
How to Make an Amazon EBS Volume Available for Use
Inside the instance, the Amazon EBS volume is exposed as a normal block device and can be formatted as any file system and mounted.
After making the Amazon EBS volume available for use, you can take snapshots of it for backup purposes or to use as baselines to launch new volumes.
Linux and UNIX
This section describes how to make a volume available to the Linux and UNIX operating system.
To create an ext3 file system on the Amazon EBS volume and mount it as /mnt/data-store
-
Enter the following command.
$
-
Enter the following command.
$
-
Enter the following command.
$
Any data written to this file system is written to the Amazon EBS volume and is transparent to applications using the device.
Windows
This section describes how to make a volume available to the Windows operating system.
To use an Amazon EBS volume
-
Log in to your instance using Remote Desktop.
-
On the taskbar, click Start, and then click Run.
-
Type diskmgmt.msc and click OK. The Disk Management utility opens.
-
Right-click the Amazon EBS volume, select New Volume, and follow the on-screen prompts.
Note If the New Volume option does not appear, select Format.
Any data written to this file system is written to the Amazon EBS volume and is transparent to applications using the device.
How to Create an Amazon EBS Snapshot
After writing data to an Amazon EBS volume, you can periodically create a snapshot of the volume to use as a baseline for new volumes or for data backup.
Note | |
---|---|
Snapshots occur asynchronously and the status settings of volumes indicate "pending" until they complete. For information on creating an Amazon EBS volume from a snapshot, see Amazon Elastic Block Store. |
Procedure
To create a snapshot
-
If you are using SOAP, construct the following request:
<CreateSnapshot xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <volumeId>
volume-id
</volumeId> </CreateSnapshot> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=CreateSnapshot &VolumeId=
volume-id
&...auth parameters... -
View output similar to the following:
<CreateSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <snapshotId>snap-78a54011</snapshotId> <volumeId>vol-4d826724</volumeId> <status>pending</status> <startTime>2008-05-07T12:51:50.000Z</startTime> <progress></progress> </CreateSnapshotResponse>
How to Describe Snapshots
This section describes how to view snapshots that you created.
Note | |
---|---|
When the snapshot is complete, its status will change to |
Procedure
To describe snapshots
-
If you are using SOAP, construct the following request:
<DescribeSnapshots xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <snapshotId>
snapshot-id
</snapshotId> </DescribeSnapshots> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=DescribeSnapshots &SnapshotId=
snapshot-id
&...auth parameters... -
View output similar to the following:
<DescribeSnapshotsResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <snapshotSet> <item> <snapshotId>snap-78a54011</snapshotId> <volumeId>vol-4d826724</volumeId> <status>pending</status> <startTime>2008-05-07T12:51:50.000Z</startTime> <progress>80%</progress> </item> </snapshotSet> </DescribeSnapshotsResponse>
How to Detach an Amazon EBS Volume from an Instance
An Amazon EBS volume can be detached from an instance by either explicitly detaching the volume or terminating the instance. This example unmounts the volume and explicitly detaches it from the instance. This is useful when you want to terminate an instance or attach a volume to a different instance.
Caution | |
---|---|
A volume must be unmounted inside the instance before being detached. Failure to do so will result in damage to the file system or the data it contains. |
To verify the volume is no longer attached to the instance, see How to Describe Snapshots.
Procedure
To detach an Amazon EBS volume
-
If you are using SOAP, construct the following request:
<DetachVolume xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <volumeId>
volume-id
</volumeId> <instanceId>instance-id
</instanceId> </DetachVolume> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=DetachVolume &VolumeId=
volume-id
&InstanceId=instance-id
&...auth parameters... -
View output similar to the following:
<DetachVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <volumeId>vol-4d826724</volumeId> <instanceId>i-6058a509</instanceId> <device>/dev/sdh</device> <status>detaching</status> <attachTime>2008-05-08T11:51:50.000Z</attachTime> </DetachVolumeResponse>
How to Delete an Amazon EBS Snapshot
After a snapshot is no longer needed, it can be deleted. This section describes how to delete a snapshot.
Procedure
To delete a snapshot
-
If you are using SOAP, construct the following request:
<DeleteSnapshot xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <snapshotId>
snapshot-id
</snapshotId> </DeleteSnapshot> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=DeleteSnapshot &SnapshotId=
snapshot-id
&...auth parameters... -
View output similar to the following:
<DeleteSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <return>true</return> </DeleteSnapshotResponse>
How to Delete an Amazon EBS Volume
After a volume is no longer needed, it can be deleted. Once deleted, its data is deleted and it cannot be attached to any instance. However, you can store a snapshot of the volume that you can use to recreate it later.
This section describes how to delete a volume.
Procedure
To delete a volume
-
If you are using SOAP, construct the following request:
<DeleteVolume xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <volumeId>
volume-id
</volumeId> </DeleteVolume> -
If you are using Query, construct the following request:
https://ec2.amazonaws.com/ ?Action=DeleteVolume &VolumeId=
volume-id
&...auth parameters... -
View output similar to the following:
<DeleteVolumeResponse xmlns="http://ec2.amazonaws.com/doc/2009-07-15/"> <return>true</return> </DeleteVolumeResponse>