amazon-web-servicesamazon-ec2autoscalingamazon-ecsaws-ecs

Launch ECS Service on a specific Autoscaling Group in a Cluster


I have one ECS Cluster with two ASGs. The ASGs use different AMIs. Also, I have two ECS Services.

Each service needs to be launched on a different ASG (one reason is the services require different AMIs).

In other words, I'd like to run Service 1 on ASG 1 and the Service 2 on ASG 2, with both ASGs in the same Cluster.

Given a Cluster, I can't find a way to point a service to a specific ASG. One hack I've managed to work around this problem is creating two ECS Clusters with one ASG each.

AWS ECS Service Documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-service.html


Solution

  • Use ECS task placement constraints.

    You can use built-in attribute ecs.ami-id directly, or you can define custom attributes by ASG.