Skip to content

Instantly share code, notes, and snippets.

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 jaytaylor/f36e24fab4a6dba6823099699c97aa1a to your computer and use it in GitHub Desktop.
Save jaytaylor/f36e24fab4a6dba6823099699c97aa1a to your computer and use it in GitHub Desktop.
AWS EC2 AMI-ID finder for Ubuntu 16.04 Xenial.
#!/usr/bin/env bash
##
# Description
#
# AWS EC2 AMI-ID finder for Ubuntu 16.04 Xenial.
#
set -o errexit
set -o pipefail
set -o nounset
set -x
aws ec2 \
--region ap-southeast-2 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=ubuntu/images/hvm-ssd/*16.04*' \
--query 'Images[*].{ImageId:ImageId,Name:Name}' \
| jq 'map(select(.Name | test("-server-[0-9]{8}$"))) | sort_by(.Name) | reverse | .[0].ImageId'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment