如何在CloudFormation中使用ECS placementConstraints

时间:2017-03-14 17:57:14

标签: amazon-web-services amazon-cloudformation amazon-ecs

我正在尝试使用CloudFormation在我的服务定义中使用placementConstraints,但它并不作为AWS::ECS::Service资源中的属性存在。有解决方法吗?

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

CloudFormation ECS服务资源:http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-service.html

2 个答案:

答案 0 :(得分:1)

在撰写本文时,

PlacementConstraint作为AWS::ECS::Service的属性存在。引用AWS文档:

  

PlacementConstraint是AWS :: ECS :: Service资源的一个属性   指定服务中任务的放置约束   与Amazon EC2容器服务(Amazon ECS)关联   服务。

<强>价:

[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

答案 1 :(得分:0)

这对我有用!如果您使用yaml错误缩进可能会导致此错误。

  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

如果这不适合您,请在此处发布您的cfn文件!