Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe
Created October 13, 2017 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmikecrowe/4ca45170f5c0b072c1438837150ad81d to your computer and use it in GitHub Desktop.
Save drmikecrowe/4ca45170f5c0b072c1438837150ad81d to your computer and use it in GitHub Desktop.
Search for the latest releases for a given search string. Assumes that vendors release in bulk, so it looks for over 2 images released in a day and shows those matches
#!/bin/bash
LINES=6
if [ $# -ne 1 ];then
echo "Usage:"
echo " $0 keyword"
exit 1
fi
# REGION=us-east-1
# aws ec2 describe-images --region $REGION --query "Images[*].[CreationDate]" --filters "Name=name,Values=*$1*" --output text | cut -b -10 | sort -k1 -r | uniq -c | awk '{ if ($1 > 1) print $2 }' | sort -r | head -n 1
# exit 1
REGIONS="us-east-1 us-east-2 us-west-1 us-west-2"
for REGION in $REGIONS; do
echo "$REGION: "
DATE=$(aws ec2 describe-images --region $REGION --query "Images[*].[CreationDate]" --filters "Name=name,Values=*$1*" --output text | cut -b -10 | sort -k1 -r | uniq -c | awk '{ if ($1 > 1) print $2 }' | sort -r | head -n 1)
aws ec2 describe-images \
--region $REGION \
--query "Images[*].[ImageId,CreationDate,Name]" \
--filters "Name=name,Values=*$1*" \
--output text | grep "$DATE"
echo " "
done
@drmikecrowe
Copy link
Author

Output for search-aws-amis.sh 'ubuntu*16.04'

us-east-1:
ami-15e12b6f    2017-10-13T20:48:22.000Z        ubuntu/images/hvm-instance/ubuntu-xenial-16.04-amd64-server-20171011
ami-2aed2750    2017-10-13T20:41:11.000Z        ubuntu/images/ubuntu-xenial-16.04-amd64-server-20171011
ami-65d11b1f    2017-10-13T19:46:18.000Z        ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20171011
ami-bcdc16c6    2017-10-13T19:36:50.000Z        ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171011

us-east-2:
ami-095c706c    2017-10-13T20:51:13.000Z        ubuntu/images/hvm-instance/ubuntu-xenial-16.04-amd64-server-20171011
ami-285d714d    2017-10-13T19:48:08.000Z        ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20171011
ami-49426e2c    2017-10-13T19:37:47.000Z        ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171011
ami-9d5e72f8    2017-10-13T20:44:54.000Z        ubuntu/images/ubuntu-xenial-16.04-amd64-server-20171011

us-west-1:
ami-1b17257b    2017-10-13T19:37:35.000Z        ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171011
ami-68142608    2017-10-13T19:47:47.000Z        ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20171011
ami-781a2818    2017-10-13T20:44:05.000Z        ubuntu/images/ubuntu-xenial-16.04-amd64-server-20171011
ami-9b1a28fb    2017-10-13T20:50:37.000Z        ubuntu/images/hvm-instance/ubuntu-xenial-16.04-amd64-server-20171011

us-west-2:
ami-19e92861    2017-10-13T19:37:31.000Z        ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171011
ami-47eb2a3f    2017-10-13T19:47:34.000Z        ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20171011
ami-7ff13007    2017-10-13T20:43:41.000Z        ubuntu/images/ubuntu-xenial-16.04-amd64-server-20171011
ami-d1ec2da9    2017-10-13T20:50:22.000Z        ubuntu/images/hvm-instance/ubuntu-xenial-16.04-amd64-server-20171011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment