我正在使用 aws-cli v2 从 AWS Describe-volumes 获取 --query 输出。在此,我尝试获取卷 ID、大小、实例 ID、状态。实例 ID 嵌套在 AWS Describe-volumes 中。
来源 :
{
"Volumes": [
{
"Attachments": [
{
"AttachTime": "2017-11-21T16:12:57+00:00",
"Device": "/dev/sda1",
"InstanceId": "i-0e*******",
"State": "attached",
"VolumeId": "vol-0a******",
"DeleteOnTermination": true
}
],
"AvailabilityZone": "us-east-1b",
"CreateTime": "2017-11-21T16:12:57.122000+00:00",
"Encrypted": false,
"Size": 50,
"SnapshotId": "snap-002********",
"State": "in-use",
"VolumeId": "vol-0a6d8675a63b65c20",
"Iops": 150,
"VolumeType": "gp2",
"MultiAttachEnabled": false
},
目前我能够获得表格输出,但只能在两个小表中。但我希望输出在单个表中。
aws ec2 describe-volumes --query "Volumes[*].{Size:Size,State:State,Type:VolumeType,Attachments[Instance:InstanceId],Volume:VolumeId}" --output table
| DescribeVolumes |
+------+---------+-------+--------------------------+
| Size | State | Type | Volume |
+------+---------+-------+--------------------------+
| 10 | in-use | gp2 | vol-0a468f3b9a1762acc |
+------+---------+-------+--------------------------+
|| InstanceID ||
|+-------------------------------------------------+|
|| i-0d5a6a29093a7039f ||
|+-------------------------------------------------+|
有没有办法将 DescribeVolumes 和 InstanceID 表合并到一个表中。例如
------------------------------------------------------------------------
| DescribeVolumes |
+----------+-------+------------+-----------+--------------------------+
| Instance | Size | State | Type | Volume |
+----------+-------+------------+-----------+--------------------------+
| None | 50 | in-use | gp2 | vol-0a6d************* |
答案1
如果您可以假设不会有多个附件,则可以使用:
aws ec2 describe-volumes --query "Volumes[*].{Size:Size,State:State,Type:VolumeType,Instance:Attachments[0].InstanceId,Volume:VolumeId}" --output table