Last active
August 29, 2017 18:40
-
-
Save snandam/8c54537b512815f6b0403c356be05bcf to your computer and use it in GitHub Desktop.
Search for latest AWS AMI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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