Last Updated: September 07, 2016
·
2.562K
· Lorin Hochstein

Get AMI id and snapshot ID by tag

Get the AMI and snapshot ID for a given EC2 image using awscli and jq. For example, if we have an image that has source=packer as a tag:

$ aws ec2 describe-images --filter Name=tag:source,Values=packer | jq ".Images[0].ImageId,.Images[0].BlockDeviceMappings[0].Ebs.SnapshotId" 

{
  "snap": "snap-2e2d50c3",
  "ami": "ami-43e0ab01"
}

1 Response
Add your response

The AWS command-line interface has --query which you can use instead of jq, although the syntax is slightly different (JMESPath) it eliminates the dependency. :)

over 1 year ago ·