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:


I have released my new course on Udemy, Kubernetes By Example. Sign up now to get free lifetime access!
$ 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