Below are given the ways to find latest ec2 Ubuntu Ami using Aws-cli, Terraform and Cloudformation.
1. To find latest Ubuntu Ami using Aws-cli ————
echo “Finding latest Ubuntu Image”
image_ID=$(aws ec2 describe-images \
–owners 099720109477 \
–filters Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-focal-* \
–query ‘sort_by(Images,&CreationDate)[-1].ImageId’ \
–output text)
echo $image_ID
2. To find latest Ubuntu Ami using Terraform ————-
ami = data.aws_ami.ubuntu_ami.id
————————————————–
data “aws_ami” “ubuntu_ami” {
most_recent = true
owners = [“099720109477”]
filter {
name = “name”
values = [“ubuntu/images/hvm-ssd/ubuntu-*”]
}
3. To find latest Ubuntu Ami using Cloudformation ————-
“Parameters”: {
“UbuntuLatestAmiId” : {
“Type” : “AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>”,
“Default”: “/aws/service/canonical/ubuntu/server/focal/
stable/current/amd64/hvm/ebs-gp2/ami-id”
}
}
—————————————–
“ImageId” : { “Ref” : “UbuntuLatestAmiId” }
- This topic has 1 reply, 1 voice, and was last updated 1 year, 10 months ago.
You must be logged in to reply to this topic.