Last active
February 11, 2021 00:28
-
-
Save nmarley/216c0f4e8e6d768de3f00c45548ed6d1 to your computer and use it in GitHub Desktop.
AWS EC2: Search most recent Ubuntu AMI for all regions
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 | |
# search based on prefix and most recent date | |
IMAGE_PREFIX="ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-" | |
# Canonical (makers of Ubuntu) | |
OWNER_ID="099720109477" | |
for REGION in $(aws ec2 describe-regions | jq -r '.Regions[].RegionName'); do | |
IMAGE_ID=$(aws ec2 describe-images --region "${REGION}" --filters "Name=name,Values=${IMAGE_PREFIX}*" --owners "$OWNER_ID" | jq -r '.Images | sort_by(.CreationDate)[-1].ImageId') | |
echo "${REGION}:" | |
echo " AMI: ${IMAGE_ID}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment