diff --git a/ecs-service.cfndsl.rb b/ecs-service.cfndsl.rb index 8262dc5..7b7bf75 100644 --- a/ecs-service.cfndsl.rb +++ b/ecs-service.cfndsl.rb @@ -427,6 +427,7 @@ strategy = external_parameters.fetch(:scheduling_strategy, nil) + task_placement_distinct_instance_constraint = external_parameters.fetch(:distinct_instance_constraint, false) health_check_grace_period = external_parameters.fetch(:health_check_grace_period, nil) placement_strategies = external_parameters.fetch(:placement_strategies, nil) ECS_Service('Service') do @@ -444,6 +445,7 @@ TaskDefinition Ref('Task') SchedulingStrategy scheduling_strategy if !strategy.nil? PlacementStrategies placement_strategies if !placement_strategies.nil? + PlacementConstraints [{Type: "distinctInstance"}] if task_placement_distinct_instance_constraint if service_loadbalancer.any? Role Ref('Role') unless awsvpc_enabled diff --git a/ecs-service.config.yaml b/ecs-service.config.yaml index 03e2c53..123d4cf 100644 --- a/ecs-service.config.yaml +++ b/ecs-service.config.yaml @@ -13,9 +13,10 @@ log_retention: 7 # # volumes: # - data-volume:/data -# NOTE: task placement constraint only suport Type="memberOf" +# NOTE: task_placement_constraint only suport Type="memberOf". Use distinct_instance_constraint: true for Type="distinctInstance" # task_placement_constraints: # - "attribute:ecs.availability-zone==ap-southeast-2a" +# distinct_instance_constraint: true # # placement_strategies: # - Field: memory