6 ms·
I'm using this tool with curl in scripts calling AWS api. Looking for an id of an object (security group, autoscaling group etc.) with its name and referencing
by mathieuruellan 12y ago
I'm using this tool with curl in scripts calling AWS api. Looking for an id of an object (security group, autoscaling group etc.) with its name and referencing it afterward in another command.
- pavel_lishin 12y agoHey, me too! It's pretty awesome, although the documentation/examples aren't as great as they could be - it took me some time to figure out how to properly parse arrays, and I'm still not sure how to actually do what I want to do (I want to convert an array of two instance objects into an array with just two instance IDs.
- mh- 12y ago% aws ec2 describe-instances --instance-ids '["i-3026a249","i-28739551"]' \ | jq '[.Reservations[].Instances[].InstanceId]' [ "i-28739551", "i-3026a249" ]
- pavel_lishin 12y agoThanks!
- gatehouse 12y agoI've been using it for the exact same thing. One difficulty that I had was that you need to use the raw option, "jq -r" for string output without quotes, but I was looking at the query language documentation and not finding it. EDIT: here is one I used. Given VOLUME_ID, gets the most recent snapshot-id. SNAPSHOT_ID=$(\ aws ec2 describe-snapshots --owner-ids xxxxxxxxxxxx --output json | jq -r " .Snapshots | sort_by(.StartTime) | reverse[] | select(.VolumeId==\"$VOLUME_ID\" and .State==\"completed\") | .SnapshotId ") EDIT2: now that I'm looking at it, I think that I expected it to work with multiple snapshots but I'm not sure that I tested it.
- mentat 12y agoI've been using this to transform the output of ElasticBeanstalk environment queries into things I can feed into environment updates since moving between versions is a PITA. Should post that code sometime...