Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default image is not the recommended one #47

Open
WhyNotHugo opened this issue Apr 8, 2021 · 1 comment
Open

Default image is not the recommended one #47

WhyNotHugo opened this issue Apr 8, 2021 · 1 comment

Comments

@WhyNotHugo
Copy link

The image used by default does not match the image recommended by AWS for ECS.

This returns amzn2-ami-ecs-gpu-hvm-2.0.20210331-x86_64-ebs:

# Get latest Linux 2 ECS-optimized AMI by Amazon
data "aws_ami" "latest_ecs_ami" {
  most_recent = true

  filter {
    name   = "name"
    values = ["amzn2-ami-ecs-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["amazon"]
}

The recommended image, mentioned here, can be obtained with:

aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux-2/recommended | jq -r '.Parameters[0].Value' | jq .image_id

The image id is amzn2-ami-ecs-hvm-2.0.20210331-x86_64-ebs, and this can be fetched with terraform using:

data "aws_ssm_parameter" "ecs_optimised_ami" {
  name = "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended"
}

resource "aws_instance" "myinstance" {
  ami = jsondecode(data.aws_ssm_parameter.ecs_optimised_ami.value)["image_id"]
}
@mrtaxi
Copy link

mrtaxi commented Feb 23, 2023

you can simply change the block:

data "aws_ami" "latest_ecs_ami" {
  most_recent = true

  filter {
    name   = "name"
    values = ["amzn2-ami-ecs-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["amazon"]
}

to this block:

data "aws_ami" "latest_ecs_ami" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn2-ami-ecs-hvm-*-x86_64-ebs"]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants