この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
volume(ボリューム)に関する操作
EBS関連コマンドは以下の9つ。
attach-volume
create-volume
delete-volume
describe-volumes
detach-volume
import-volume
describe-volume-attribute
modify-volume-attribute
describe-volume-status
create-volume
ボリュームを作成します。アベイラビリティゾーンが必須、容量(GB指定)、snapshot-id(volume-type, iops)についてはオプション指定が可能となっています。
$ aws ec2 create-volume --region ap-northeast-1 --availability-zone ap-northeast-1c --size 7
{
"AvailabilityZone": "ap-northeast-1c",
"Attachments": [],
"ResponseMetadata": {
"RequestId": "b0a597b2-c04a-46d8-a741-7e4673d959ad"
},
"Tags": [],
"VolumeType": "standard",
"VolumeId": "vol-3965b61c",
"State": "creating",
"SnapshotId": null,
"CreateTime": "2013-07-17T07:45:46.000Z",
"Size": 7
}
ちなみにアベイラビリティゾーンは以下の『describe-availability-zones』コマンドにて、指定のリージョンに対応しているAZを取得する事が出来ます。
$ aws ec2 describe-availability-zones --region ap-northeast-1
{
"AvailabilityZones": [
{
"State": "available",
"ZoneName": "ap-northeast-1a",
"Messages": [],
"RegionName": "ap-northeast-1"
},
{
"State": "available",
"ZoneName": "ap-northeast-1b",
"Messages": [],
"RegionName": "ap-northeast-1"
},
{
"State": "available",
"ZoneName": "ap-northeast-1c",
"Messages": [],
"RegionName": "ap-northeast-1"
}
],
"ResponseMetadata": {
"RequestId": "088aeb98-1ee5-427f-b6af-701842b56d23"
}
}
delete-volume
任意のボリュームを削除します。
$ aws ec2 delete-volume --volume-id vol-3965b61c --region ap-northeast-1
{
"return": "true",
"ResponseMetadata": {
"RequestId": "e6482324-3611-40d4-95d2-64164ccddbc8"
}
}
describe-volumes
アカウントに紐付くボリュームの一覧を表示します。ボリュームIDによる絞込等も可能です。
$ aws ec2 describe-volumes --region ap-northeast-1 | jq '.Volumes | length'
5
$
$ aws ec2 describe-volumes --region ap-northeast-1
{
"ResponseMetadata": {
"RequestId": "e89a30e6-c7c7-44aa-a4d9-e525679929c8"
},
"Volumes": [
{
"AvailabilityZone": "ap-northeast-1a",
"Attachments": [
{
"AttachTime": "2013-07-16T11:23:01.000Z",
"InstanceId": "i-da2574d8",
"VolumeId": "vol-cb5d8dee",
"State": "attached",
"DeleteOnTermination": true,
"Device": "/dev/sda1"
}
],
"VolumeType": "standard",
"VolumeId": "vol-cb5d8dee",
"State": "in-use",
"SnapshotId": "snap-826a82a0",
"CreateTime": "2013-07-16T11:23:00.000Z",
"Size": 8
},
{
"AvailabilityZone": "ap-northeast-1c",
"Attachments": [],
"VolumeType": "standard",
"VolumeId": "vol-3965b61c",
"State": "available",
"SnapshotId": null,
"CreateTime": "2013-07-17T07:45:46.000Z",
"Size": 7
},
:
:
]
}
attach-volume
EBSを所定のEC2にアタッチ(取り付け)します。以下例はエラーの場合。volumeをインスタンスとは異なるAZで作成していた為怒られてしまいました。
$ aws ec2 attach-volume --instance-id i-6a8ec568 --device /dev/sda2 --volume-id vol-3965b61c --region ap-northeast-1
{
"Errors": [
{
"Message": "The volume 'vol-3965b61c' is not in the same availability zone as instance 'i-6a8ec568'",
"Code": "InvalidVolume.ZoneMismatch"
}
],
"ResponseMetadata": {
"RequestId": "bb5b9cd3-c1bb-4bd0-a7b0-707839a866a6"
}
}
EC2インスタンスとボリュームを同じAZ(ap-northeast-1c)に作成する事でattach出来ました。
$ aws ec2 attach-volume --instance-id i-e4a9f9e6 --device /dev/sda2 --volume-id vol-3965b61c --region ap-northeast-1
{
"ResponseMetadata": {
"RequestId": "571ee58b-0486-4510-b914-197d760cbb51"
},
"AttachTime": "2013-07-17T08:18:14.517Z",
"InstanceId": "i-e4a9f9e6",
"VolumeId": "vol-3965b61c",
"State": "attaching",
"Device": "/dev/sda2"
}
detach-volume
EC2からボリュームをデタッチ(切り離し)します。
$ aws ec2 detach-volume --instance-id i-e4a9f9e6 --volume-id vol-3965b61c --region ap-northeast-1
{
"ResponseMetadata": {
"RequestId": "af1f24a6-0071-41f6-a8c9-4fa2c896cd37"
},
"AttachTime": "2013-07-17T08:18:14.000Z",
"InstanceId": "i-e4a9f9e6",
"VolumeId": "vol-3965b61c",
"State": "detaching",
"Device": "/dev/sda2"
}
import-volume
名前の通り、ボリュームをインポートします。なのですが、情報収集し切れず。このコマンドはひとまず保留。
describe-volume-attribute
ボリュームの属性情報を表示します。--attribute指定無しだとこうなるので何らかの指定が必要なのですが、ヘルプを見る限りだとどのような値が指定可能かどうかの記載は無い模様。
$ aws ec2 describe-volume-attribute --volume-id vol-3965b61c --region ap-northeast-1
{
"AutoEnableIO": {},
"ProductCodes": [],
"Errors": [
{
"Message": "No attributes specified.",
"Code": "InvalidParameterCombination"
}
],
"ResponseMetadata": {
"RequestId": "c57b98a2-e507-41bc-a05a-8665a4555dc6"
}
}
modify-volume-attribute
ボリューム属性に関する情報を変更します。
現行、ヘルプを見る限りだと変更可能な値は、『--auto-enable-io』の1つのみ。
管理コンソールにおけるこの部分をカバーするコマンドのようですが....(ボリュームのモニタリングを有効/無効にする設定)
アカンようですね...(・ω・`)
$ aws ec2 modify-volume-attribute --volume-id vol-3965b61c --auto-enable-io true
Unknown options: ['true']
describe-volume-status
ボリュームのステータスに関する情報を一覧表示します。ボリュームIDによる絞込等も可能です。
$ aws ec2 describe-volume-status --region ap-northeast-1
[
{
"VolumeStatus": {
"Status": "ok",
"Details": [
{
"Status": "passed",
"Name": "io-enabled"
},
{
"Status": "not-applicable",
"Name": "io-performance"
}
]
},
"AvailabilityZone": "ap-northeast-1a",
"VolumeId": "vol-cb5d8dee",
"Actions": [],
"Events": []
},
{
"VolumeStatus": {
"Status": "ok",
"Details": [
{
"Status": "passed",
"Name": "io-enabled"
},
{
"Status": "not-applicable",
"Name": "io-performance"
}
]
},
"AvailabilityZone": "ap-northeast-1c",
"VolumeId": "vol-3965b61c",
"Actions": [],
"Events": []
},
:
:
]