Service

class Service : KotlinCustomResource

Note: To prevent a race condition during service deletion, make sure to set depends_on to the related aws.iam.RolePolicy; otherwise, the policy may be destroyed too soon and the ECS service will then get stuck in the DRAINING state. 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). See ECS Services section in AWS developer guide.

Example Usage

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ecs.Service;
import com.pulumi.aws.ecs.ServiceArgs;
import com.pulumi.aws.ecs.inputs.ServiceOrderedPlacementStrategyArgs;
import com.pulumi.aws.ecs.inputs.ServiceLoadBalancerArgs;
import com.pulumi.aws.ecs.inputs.ServicePlacementConstraintArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var mongo = new Service("mongo", ServiceArgs.builder()
.cluster(aws_ecs_cluster.foo().id())
.taskDefinition(aws_ecs_task_definition.mongo().arn())
.desiredCount(3)
.iamRole(aws_iam_role.foo().arn())
.orderedPlacementStrategies(ServiceOrderedPlacementStrategyArgs.builder()
.type("binpack")
.field("cpu")
.build())
.loadBalancers(ServiceLoadBalancerArgs.builder()
.targetGroupArn(aws_lb_target_group.foo().arn())
.containerName("mongo")
.containerPort(8080)
.build())
.placementConstraints(ServicePlacementConstraintArgs.builder()
.type("memberOf")
.expression("attribute:ecs.availability-zone in [us-west-2a, us-west-2b]")
.build())
.build(), CustomResourceOptions.builder()
.dependsOn(aws_iam_role_policy.foo())
.build());
}
}

Ignoring Changes to Desired Count

You can use ignoreChanges to create an ECS service with an initial count of running instances, then ignore any changes to that count caused externally (e.g. Application Autoscaling).

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ecs.Service;
import com.pulumi.aws.ecs.ServiceArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new Service("example", ServiceArgs.builder()
.desiredCount(2)
.build());
}
}

Daemon Scheduling Strategy

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ecs.Service;
import com.pulumi.aws.ecs.ServiceArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var bar = new Service("bar", ServiceArgs.builder()
.cluster(aws_ecs_cluster.foo().id())
.taskDefinition(aws_ecs_task_definition.bar().arn())
.schedulingStrategy("DAEMON")
.build());
}
}

CloudWatch Deployment Alarms

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ecs.Service;
import com.pulumi.aws.ecs.ServiceArgs;
import com.pulumi.aws.ecs.inputs.ServiceAlarmsArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new Service("example", ServiceArgs.builder()
.cluster(aws_ecs_cluster.example().id())
.alarms(ServiceAlarmsArgs.builder()
.enable(true)
.rollback(true)
.alarmNames(aws_cloudwatch_metric_alarm.example().alarm_name())
.build())
.build());
}
}

External Deployment Controller

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ecs.Service;
import com.pulumi.aws.ecs.ServiceArgs;
import com.pulumi.aws.ecs.inputs.ServiceDeploymentControllerArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new Service("example", ServiceArgs.builder()
.cluster(aws_ecs_cluster.example().id())
.deploymentController(ServiceDeploymentControllerArgs.builder()
.type("EXTERNAL")
.build())
.build());
}
}

Import

ECS services can be imported using the name together with ecs cluster name, e.g.,

$ pulumi import aws:ecs/service:Service imported cluster-name/service-name

Properties

Link copied to clipboard
val alarms: Output<ServiceAlarms>?

Information about the CloudWatch alarms. See below.

Link copied to clipboard

Capacity provider strategies to use for the service. Can be one or more. These can be updated without destroying and recreating the service only if force_new_deployment = true and not changing from 0 capacity_provider_strategy blocks to greater than 0, or vice versa. See below.

Link copied to clipboard
val cluster: Output<String>

ARN of an ECS cluster.

Link copied to clipboard

Configuration block for deployment circuit breaker. See below.

Link copied to clipboard

Configuration block for deployment controller configuration. See below.

Link copied to clipboard

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. Not valid when using the DAEMON scheduling strategy.

Link copied to clipboard

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.

Link copied to clipboard
val desiredCount: Output<Int>?

Number of instances of the task definition to place and keep running. Defaults to 0. Do not specify if using the DAEMON scheduling strategy.

Link copied to clipboard

Specifies whether to enable Amazon ECS managed tags for the tasks within the service.

Link copied to clipboard

Specifies whether to enable Amazon ECS Exec for the tasks within the service.

Link copied to clipboard

Enable to force a new task deployment of the service. This can be used to update tasks to use a newer Docker image with same image/tag combination (e.g., myimage:latest), roll Fargate tasks onto a newer platform version, or immediately deploy ordered_placement_strategy and placement_constraints updates.

Link copied to clipboard

Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 2147483647. Only valid for services configured to use load balancers.

Link copied to clipboard
val iamRole: Output<String>

ARN of the IAM role that allows Amazon ECS to make calls to your load balancer on your behalf. This parameter is required if you are using a load balancer with your service, but only if your task definition does not use the awsvpc network mode. If using awsvpc network mode, do not specify this role. If your account has already created the Amazon ECS service-linked role, that role is used by default for your service unless you specify a role here.

Link copied to clipboard
val id: Output<String>
Link copied to clipboard
val launchType: Output<String>

Launch type on which to run your service. The valid values are EC2, FARGATE, and EXTERNAL. Defaults to EC2.

Link copied to clipboard

Configuration block for load balancers. See below.

Link copied to clipboard
val name: Output<String>

Name of the service (up to 255 letters, numbers, hyphens, and underscores) The following arguments are optional:

Link copied to clipboard

Network configuration for the service. This parameter is required for task definitions that use the awsvpc network mode to receive their own Elastic Network Interface, and it is not supported for other network modes. See below.

Link copied to clipboard

Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. Updates to this configuration will take effect next task deployment unless force_new_deployment is enabled. The maximum number of ordered_placement_strategy blocks is 5. See below.

Link copied to clipboard

Rules that are taken into consideration during task placement. Updates to this configuration will take effect next task deployment unless force_new_deployment is enabled. Maximum number of placement_constraints is 10. See below.

Link copied to clipboard
val platformVersion: Output<String>

Platform version on which to run your service. Only applicable for launch_type set to FARGATE. Defaults to LATEST. More information about Fargate platform versions can be found in the AWS ECS User Guide.

Link copied to clipboard
val propagateTags: Output<String>?

Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION.

Link copied to clipboard
val pulumiChildResources: Set<KotlinResource>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Scheduling strategy to use for the service. The valid values are REPLICA and DAEMON. Defaults to REPLICA. Note that Tasks using the Fargate launch type or the CODE_DEPLOY or EXTERNAL deployment controller types don't support the DAEMON scheduling strategy.

Link copied to clipboard

The ECS Service Connect configuration for this service to discover and connect to services, and be discovered by, and connected from, other services within a namespace. See below.

Link copied to clipboard

Service discovery registries for the service. The maximum number of service_registries blocks is 1. See below.

Link copied to clipboard
val tags: Output<Map<String, String>>?

Key-value map of resource tags. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

Link copied to clipboard
val tagsAll: Output<Map<String, String>>

A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

Link copied to clipboard
val taskDefinition: Output<String>?

Family and revision (family:revision) or full ARN of the task definition that you want to run in your service. Required unless using the EXTERNAL deployment controller. If a revision is not specified, the latest ACTIVE revision is used.

Link copied to clipboard
val triggers: Output<Map<String, String>>

Map of arbitrary keys and values that, when changed, will trigger an in-place update (redeployment). Useful with timestamp(). See example above.

Link copied to clipboard
val urn: Output<String>
Link copied to clipboard

If true, this provider will wait for the service to reach a steady state (like aws ecs wait services-stable) before continuing. Default false.