LookupAMI

nicolaw 25th February 2019 at 4:11pm
AWS awscli jq JSON Terraform
while read -r region; do
  image_id=$(aws ec2 describe-images \
         --region "$region" \
         --owners 'aws-marketplace' \
         --filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' \
         --query 'sort_by(Images, &CreationDate)[-1].ImageId' \
         --output text)
  printf '%s=%s\n' "$region" "$image_id"
done < <(aws ec2 describe-regions --output text \
             --query 'Regions[].{Name:RegionName}')
data "aws_ami" "amazon_linux" {
  most_recent = true
  owners      = ["amazon"]
  filter {
    name = "name"
    values = ["amzn-ami-*-amazon-ecs-optimized"]
  }
}