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”: {
“WindowsLatestAmiId” : {
“Type” : “AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>”,
“Default”: “/aws/service/ami-windows-latest/
Windows_Server-2019-English-Full-Base”
}
}
—————————————–
“ImageId” : { “Ref” : “WindowsLatestAmiId” }
-
This reply was modified 2 years, 1 month ago by
Harjap.