AWS – Get the latest Windows AMI’s

The fastest way to get a list of available AMI’s in AWS is to use the AWS CLI.

If you have not used it yet go here and learn it!

For this we use the ‘ec2 describe-images’ base command;

aws ec2 describe-images --owners amazon \
--filters \
Name=root-device-type,Values=ebs \
Name=architecture,Values=x86_64 \
Name=name,Values=*Windows_Server-2012-R2_RTM-English*Base*

That gets us is a huge list of all Windows 2012 R2 AMI’s.
What we need to do is filter, that is easy using JMESPath.

…lets filter the return by selecting just the Name, ImageId and CreatedDate.

aws ec2 describe-images --owners amazon \
--filters \
Name=root-device-type,Values=ebs \
Name=architecture,Values=x86_64 \
Name=name,Values=*Windows_Server-2012-R2_RTM-English*Base* \
--query 'Images[].{ID:ImageId,Name:Name,Created:CreationDate}'

So better but still a lot of AMI’s to look through.
Lets filter by CreationDate, get all AMI’s created after May-01 2017.

aws ec2 describe-images --owners amazon \
--filters \
Name=root-device-type,Values=ebs \
Name=architecture,Values=x86_64 \
Name=name,Values=*Windows_Server-2012-R2_RTM-English*Base* \
--query 'Images[?CreationDate>=`2017-06-01`][].{ID:ImageId,Name:Name,Created:CreationDate}'

So now we have a better list!

As you can see AWS CLI and JMESPath for the win!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s