2
votes

I am trying to use placementConstraints in my service definition using CloudFormation, but it does not exist as property in the AWS::ECS::Service resource. Is there a workaround?

ECS Service: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_definition_paramters.html

CloudFormation ECS Service Resource: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-service.html

2

2 Answers

1
votes

PlacementConstraint exists as a property of AWS::ECS::Service at the time of this writing. Quoting from AWS docs:

PlacementConstraint is a property of the AWS::ECS::Service resource that specifies the placement constraints for the tasks in the service to associate with an Amazon EC2 Container Service (Amazon ECS) service.

Ref:

[1] http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-service-placementconstraints-placementconstraint.html

[2] http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-service.html#cfn-ecs-service-placementconstraints

0
votes

This works for me ! If you using yaml wrong indentation can lead to this error.

  ApplicationService:
    Type: AWS::ECS::Service
    DependsOn:
      - ALBListener
      - ApplicationTaskDefinition
      - ALBTargetGroup
    Properties:
      Cluster:
        'Fn::ImportValue': !Sub ecs-${EnvironmentName}-clustername
      DesiredCount: 15
      LoadBalancers:
        - ContainerName: !Sub ${AWS::StackName}-app
          ContainerPort: 8080
          TargetGroupArn: !Ref ALBTargetGroup
      Role:
        'Fn::ImportValue': !Sub ecs-${EnvironmentName}-servicerole-arn
      TaskDefinition: !Ref ApplicationTaskDefinition
      PlacementConstraints:
      - Expression: attribute:ecs.instance-type == t2.medium
        Type: memberOf
      PlacementStrategies:
      - Type: spread
        Field: attribute:ecs.availability-zone

If this not working for you please post your cfn file here !