我想从停止的ec2实例获取卷详细信息。我需要在下面的同一行中获取实例ID和卷ID。
aws ec2 describe-instances --region us-east-1 --profile <profile name> --filter Name=instance-state-name,Values=stopped,shutting-down | jq '.Reservations[].Instances[] | .InstanceId, .BlockDeviceMappings[].Ebs.VolumeId'
Actual Output
"i-f5ada1f18"
"vol-66a8adas2a2d"
"i-bb064fda12140"
"vol-52951f1dss9"
"i-3e1059sc5asd"
"vol-0da2ds122846"
Expected output
"i-f5ada1f18 vol-66a8adas2a2d"
"i-bb064fda12140 vol-52951f1dss9"
"i-3e1059sc5asd vol-0da2ds122846"
答案 0 :(得分:0)
您可以使用AWK
和sed
来尝试以下命令
aws ec2 describe-instances --region us-west-2 --filter Name=instance-state-name,Values=stopped,shutting-down | jq '.Reservations[].Instances[] | .InstanceId, .BlockDeviceMappings[].Ebs.VolumeId' | awk 'NR%2{printf "%s ",$0;next;}1' | sed 's/"//g' | sed 's/^/"/' |sed 's/$/"/'
输出
"i-36e9e2c0 vol-480d085a"
"i-090225ee5bbeb6cad vol-0f719c8f188bbec98"