CodexBloom - Programming Q&A Platform

AWS CloudFormation scenarios to Create ECS Service with scenarios 'Service placement constraint does not match any instances'

πŸ‘€ Views: 26 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-09
aws cloudformation ecs fargate YAML

I'm relatively new to this, so bear with me... This might be a silly question, but After trying multiple solutions online, I still can't figure this out. I'm trying to deploy an Amazon ECS service using AWS CloudFormation, but I'm running into an behavior that states, "Service placement constraint does not match any instances." My CloudFormation template is supposed to create an ECS cluster, a task definition, and the service itself. However, after executing the stack creation, it fails at the ECS service step. Here’s a snippet of the relevant parts of my CloudFormation template: ```yaml Resources: MyCluster: Type: 'AWS::ECS::Cluster' Properties: ClusterName: MyEcsCluster MyTaskDefinition: Type: 'AWS::ECS::TaskDefinition' Properties: Family: MyTask ContainerDefinitions: - Name: myContainer Image: myImage:latest Memory: 512 Cpu: 256 MyService: Type: 'AWS::ECS::Service' Properties: Cluster: !Ref MyCluster TaskDefinition: !Ref MyTaskDefinition DesiredCount: 1 LaunchType: FARGATE NetworkConfiguration: AwsvpcConfiguration: Subnets: - subnet-abc123 SecurityGroups: - sg-xyz456 AssignPublicIp: ENABLED PlacementConstraints: - Type: memberOf Expression: "attribute:ecs.availability-zone in ['us-east-1a', 'us-east-1b']" ``` I’ve checked that the ECS cluster is being created successfully, and my task definition looks correct as well. I'm using Fargate launch type, and I believe the security group and subnet configurations should allow for the instances to be reachable. However, the placement constraint expression seems to be the culprit. I've tried simplifying the placement constraints by removing them entirely, and the service gets created without issues. But I need those constraints to ensure the service runs in specific availability zones. Can anyone guide to understand what I might be missing with the placement constraints? Is there a specific format I should be using or something related to the ECS service setup that I may have overlooked? Thanks in advance for your assistance! Is there a better approach? Thanks for your help in advance! Is this even possible?