Skip to content

Instantly share code, notes, and snippets.

@snandam
Last active August 29, 2017 18:40
Show Gist options
  • Save snandam/8c54537b512815f6b0403c356be05bcf to your computer and use it in GitHub Desktop.
Save snandam/8c54537b512815f6b0403c356be05bcf to your computer and use it in GitHub Desktop.
Search for latest AWS AMI
#!/bin/bash
aws ec2 \
--region us-east-1 describe-images \
--filters \
'Name=architecture,Values=x86_64' \
'Name=root-device-type,Values=ebs' \
'Name=state,Values=available' \
'Name=virtualization-type,Values=hvm' \
'Name=image-type,Values=machine' \
'Name=name,Values=amzn-ami-hvm-*gp2' \
--query 'Images[*].{ImageId:ImageId,Name:Name}' \
| jq 'map(select(.Name | test("^[^rc]*$"))) | sort_by(.Name) | reverse | .[0].ImageId' -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment