Last active
March 19, 2018 05:04
-
-
Save antimius/6248477b363d0655a32a63e27af7e219 to your computer and use it in GitHub Desktop.
Script to find and print the latest stable, HVM, EBS GP2 backed EC2 AMIs from major OS vendors. Requires aws-cli to be installed. Takes a long time to complete due to AWS describe-images call being slow.
This file contains 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 | |
# prints latest, stable, HVM, EBS GP2 backed AMIs for major OSs | |
# amazon, redhat 309956199498, ubuntu 099720109477, freebsd 118940168514, CentOS marketplace code | |
REDHAT=309956199498 | |
UBUNTU=099720109477 | |
FREEBSD=118940168514 | |
MICROSOFT=801119661308 | |
REGION=${REGION:-"us-east-1"} | |
aws ec2 describe-images --region=$REGION --owners amazon --query 'Images[?Name!=`null`]|[?starts_with(Name,`amzn-ami-hvm-2016`)]|[?ends_with(Name, `gp2`)]|max_by(@, &CreationDate).[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners $UBUNTU --query 'Images[?Name!=`null`]|[?starts_with(Name,`ubuntu/images/hvm-ssd/ubuntu-xenial`)]|max_by(@, &CreationDate).[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners $UBUNTU --query 'Images[?Name!=`null`]|[?starts_with(Name,`ubuntu/images/hvm-ssd/ubuntu-trusty`)]|max_by(@, &CreationDate).[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners $REDHAT --query 'Images[?Name!=`null`]|[?starts_with(Name,`RHEL-6`)]|[?contains(Name,`GA`)]|[?ends_with(Name, `GP2`)]|max_by(@, &CreationDate).[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners $REDHAT --query 'Images[?Name!=`null`]|[?starts_with(Name,`RHEL-7`)]|[?contains(Name,`GA`)]|[?ends_with(Name, `GP2`)]|max_by(@, &CreationDate).[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners $FREEBSD --query 'Images[?Name!=`null`]|[?starts_with(Name,`FreeBSD 11.0-STABLE`)]|max_by(@, &CreationDate).[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners aws-marketplace --filters Name=product-code,Values=6x5jmcajty9edm3f211pqjfn2 --query 'Images[*].[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners aws-marketplace --filters Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce --query 'Images[*].[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners $MICROSOFT --query 'Images[?Name!=`null`]|[?starts_with(Name,`Windows_Server-2012-R2_RTM-English-64Bit-Base`)]|max_by(@, &CreationDate).[CreationDate,ImageId,Name]' --output text | |
aws ec2 describe-images --region=$REGION --owners $MICROSOFT --query 'Images[?Name!=`null`]|[?starts_with(Name,`Windows_Server-2016-English-Full-Base`)]|max_by(@, &CreationDate).[CreationDate,ImageId,Name]' --output text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: