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