Created
January 19, 2021 10:51
-
-
Save gundamew/e89855779c11e3a57fa008dcb87c4713 to your computer and use it in GitHub Desktop.
Finding a Linux AMI.
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
#!/usr/bin/env bash | |
set -euo pipefail | |
# Ref: Ref: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html | |
aws ec2 describe-images \ | |
--owners 099720109477 \ | |
--filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-*" \ | |
"Name=architecture,Values=x86_64" \ | |
"Name=virtualization-type,Values=hvm" \ | |
"Name=root-device-type,Values=ebs" | |
# Sorting results using jq | |
# Ref: http://denniswebb.info/snippet/aws-ec2-ami-sorted/ | |
aws ec2 describe-images \ | |
--owners 099720109477 \ | |
--filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-*" \ | |
"Name=architecture,Values=x86_64" \ | |
"Name=virtualization-type,Values=hvm" \ | |
"Name=root-device-type,Values=ebs" \ | |
| jq '.Images | sort_by(.CreationDate) | .[] | {Name: .Name, Created: .CreationDate, Id: .ImageId}' |
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
data "aws_ami" "ubuntu-bionic" { | |
most_recent = true | |
owners = ["099720109477"] # Canonical | |
filter { | |
name = "name" | |
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-*"] | |
} | |
filter { | |
name = "architecture" | |
values = ["x86_64"] | |
} | |
filter { | |
name = "virtualization-type" | |
values = ["hvm"] | |
} | |
filter { | |
name = "root-device-type" | |
values = ["ebs"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment