I ran an aws command and the results as below:
[root@webserver-02 test]# aws ec2 describe-volumes --volume-ids vol-0be41aaca50a1d4d2 --profile donald 2> /dev/null|
jq -r '.Volumes[]|{"Tags":(.Tags | map({(.key//.Key): (.value//.Value)}) | add), VolumeId:.VolumeId,SnapshotId:.SnapshotId, Volumesize:.Size, CreateTime:.CreateTime, State:.State,"Instances": [.Attachments[0].InstanceId] }'
and the results as below:
{
"Tags": {
"Name": "4d2",
"c": "c",
"a": "a",
"b": "b"
},
"VolumeId": "vol-0be41aaca50a1d4d2",
"SnapshotId": "snap-0be43cb27ae60c978",
"Volumesize": 8,
"CreateTime": "2018-09-20T02:24:21.067Z",
"State": "in-use",
"InstanceId": "i-016c1d0448d6917f6"
}
OK. I want to display InstanceId json as follows:
{
"Tags": {
"Name": "4d2",
"c": "c",
"a": "a",
"b": "b"
},
"VolumeId": "vol-0be41aaca50a1d4d2",
"SnapshotId": "snap-0be43cb27ae60c978",
"Volumesize": 8,
"CreateTime": "2018-09-20T02:24:21.067Z",
"State": "in-use",
"Instances": [{
"InstanceId": "i-016c1d0448d6917f6"
}]
}
I am using jq in the bash shell.