1
我正在尝试将挂载在/ dev/sdf的设备的卷id获取到特定实例。如何使用aws cli获取特定实例的/ dev/sdf中挂载设备的volumeid?
命令: AWS EC2描述体积--filters名称= attachment.instance-ID,值= $ instance_id_main --region美西2 --output JSON
输出:
{
"Volumes": [
{
"AvailabilityZone": "us-west-2a",
"Attachments": [
{
"AttachTime": "2017-06-15T12:59:18.000Z",
"InstanceId": "i-073cfdf5832e5a7ab",
"VolumeId": "vol-096ca253d37b3e42b",
"State": "attached",
"DeleteOnTermination": false,
"Device": "/dev/sdf"
}
],
"Tags": [
{
"Value": "NewVolume",
"Key": "Name"
}
],
"Encrypted": false,
"VolumeType": "gp2",
"VolumeId": "vol-096ca253d37b3e42b",
"State": "in-use",
"Iops": 100,
"SnapshotId": "",
"CreateTime": "2017-06-15T12:39:06.687Z",
"Size": 5
},
{
"AvailabilityZone": "us-west-2a",
"Attachments": [
{
"AttachTime": "2017-06-15T12:57:46.000Z",
"InstanceId": "i-073cfdf5832e5a7ab",
"VolumeId": "vol-0189e6a20392bb709",
"State": "attached",
"DeleteOnTermination": true,
"Device": "/dev/sda1"
}
],
"Tags": [
{
"Value": "NewTesting",
"Key": "Name"
}
],
"Encrypted": false,
"VolumeType": "gp2",
"VolumeId": "vol-0189e6a20392bb709",
"State": "in-use",
"Iops": 100,
"SnapshotId": "snap-0a642b1f5be55819a",
"CreateTime": "2017-06-15T12:57:46.027Z",
"Size": 8
}
]
}
我试着用--query选项来描述在这个例子中给出的音量,然后我得到了下面的输出结果。
命令:
aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=$instance_id_main --query 'Volumes[*].{ID:VolumeId,Tag:Tags}' --region us-west-2 --output json
[
{
"Tag": [
{
"Value": "NewVolume",
"Key": "Name"
}
],
"ID": "vol-096ca253d37b3e42b"
},
{
"Tag": [
{
"Value": "NewTesting",
"Key": "Name"
}
],
"ID": "vol-0189e6a20392bb709"
}
]
然后我试图让附件,我得到了下面的错误。
命令:
aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=$instance_id_main --query 'Volumes[*].{Attachments:Device[*]}' --region us-west-2 --output text
输出:
[
{
"Attachments": null
},
{
"Attachments": null
}
]
任何想法,将不胜感激。