June 9, 2018

AWS CLI with jq examples

Let’s say I have an EC2 instance with the instance id of ‘i-08725957c043b6acd’ and it has the ec2 tag: env=preprod. To pull this info out using the aws cli and jq, we run:


You can find all my latest posts on medium.
$ aws ec2 describe-tags --output json --filters "Name=resource-id,Values=i-08725987c041b6acd" | jq --raw-output '.Tags[]|select(.Key=="env")|.Value'

Note, you can obtain the instance_id locally like this:

$ instance_id=$(curl -s