github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/aws/r/ecs_service.html.markdown (about) 1 --- 2 layout: "aws" 3 page_title: "AWS: aws_ecs_service" 4 sidebar_current: "docs-aws-resource-ecs-service" 5 description: |- 6 Provides an ECS service. 7 --- 8 9 # aws\_ecs\_service 10 11 -> **Note:** To prevent a race condition during service deletion, make sure to set `depends_on` to the related `aws_iam_role_policy`; otherwise, the policy may be destroyed too soon and the ECS service will then get stuck in the `DRAINING` state. 12 13 Provides an ECS service - effectively a task that is expected to run until an error occurs or a user terminates it (typically a webserver or a database). 14 15 See [ECS Services section in AWS developer guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html). 16 17 ## Example Usage 18 19 ``` 20 resource "aws_ecs_service" "mongo" { 21 name = "mongodb" 22 cluster = "${aws_ecs_cluster.foo.id}" 23 task_definition = "${aws_ecs_task_definition.mongo.arn}" 24 desired_count = 3 25 iam_role = "${aws_iam_role.foo.arn}" 26 depends_on = ["aws_iam_role_policy.foo"] 27 28 placement_strategy { 29 type = "binpack" 30 field = "CPU" 31 } 32 33 load_balancer { 34 elb_name = "${aws_elb.foo.name}" 35 container_name = "mongo" 36 container_port = 8080 37 } 38 39 placement_constraints { 40 type = "memberOf" 41 expression = "attribute:ecs.availability-zone in [us-west-2a, us-west-2b]" 42 } 43 } 44 ``` 45 46 ## Argument Reference 47 48 The following arguments are supported: 49 50 * `name` - (Required) The name of the service (up to 255 letters, numbers, hyphens, and underscores) 51 * `task_definition` - (Required) The family and revision (`family:revision`) or full ARN of the task definition that you want to run in your service. 52 * `desired_count` - (Required) The number of instances of the task definition to place and keep running 53 * `cluster` - (Optional) ARN of an ECS cluster 54 * `iam_role` - (Optional) The ARN of IAM role that allows your Amazon ECS container agent to make calls to your load balancer on your behalf. This parameter is only required if you are using a load balancer with your service. 55 * `deployment_maximum_percent` - (Optional) The upper limit (as a percentage of the service's desiredCount) of the number of running tasks that can be running in a service during a deployment. 56 * `deployment_minimum_healthy_percent` - (Optional) The lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. 57 * `placement_strategy` - (Optional) Service level strategy rules that are taken 58 into consideration during task placement. The maximum number of 59 `placement_strategy` blocks is `5`. Defined below. 60 * `load_balancer` - (Optional) A load balancer block. Load balancers documented below. 61 * `placement_constraints` - (Optional) rules that are taken into consideration during task placement. Maximum number of 62 `placement_constraints` is `10`. Defined below. 63 64 -> **Note:** As a result of an AWS limitation, a single `load_balancer` can be attached to the ECS service at most. See [related docs](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-load-balancing.html#load-balancing-concepts). 65 66 Load balancers support the following: 67 68 * `elb_name` - (Required for ELB Classic) The name of the ELB (Classic) to associate with the service. 69 * `target_group_arn` - (Required for ALB) The ARN of the ALB target group to associate with the service. 70 * `container_name` - (Required) The name of the container to associate with the load balancer (as it appears in a container definition). 71 * `container_port` - (Required) The port on the container to associate with the load balancer. 72 73 ## placement_strategy 74 75 `placement_strategy` supports the following: 76 77 * `type` - (Required) The type of placement strategy. Must be one of: `binpack`, `random`, or `spread` 78 * `field` - (Optional) For the `spread` placement strategy, valid values are instanceId (or host, 79 which has the same effect), or any platform or custom attribute that is applied to a container instance. 80 For the `binpack` type, valid values are `memory` and `cpu`. For the `random` type, this attribute is not 81 needed. For more information, see [Placement Strategy](http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PlacementStrategy.html). 82 83 ## placement_constraints 84 85 `placement_constraints` support the following: 86 87 * `type` - (Required) The type of constraint. The only valid values at this time are `memberOf` and `distinctInstance`. 88 * `expression` - (Optional) Cluster Query Language expression to apply to the constraint. Does not need to be specified 89 for the `distinctInstance` type. 90 For more information, see [Cluster Query Language in the Amazon EC2 Container 91 Service Developer 92 Guide](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html). 93 94 95 96 ## Attributes Reference 97 98 The following attributes are exported: 99 100 * `id` - The Amazon Resource Name (ARN) that identifies the service 101 * `name` - The name of the service 102 * `cluster` - The Amazon Resource Name (ARN) of cluster which the service runs on 103 * `iam_role` - The ARN of IAM role used for ELB 104 * `desired_count` - The number of instances of the task definition