Amazon ECS services - Amazon ECS

Amazon ECS services

You can use an Amazon ECS service to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. If one of your tasks fails or stops, the Amazon ECS service scheduler launches another instance of your task definition to replace it. This helps maintain your desired number of tasks in the service.

You can also optionally run your service behind a load balancer. The load balancer distributes traffic across the tasks that are associated with the service.

Service scheduler concepts

We recommend that you use the service scheduler for long running stateless services and applications. The service scheduler ensures that the scheduling strategy that you specify is followed and reschedules tasks when a task fails. For example, if the underlying infrastructure fails, the service scheduler reschedules a task. You can use task placement strategies and constraints to customize how the scheduler places and terminates tasks. If a task in a service stops, the scheduler launches a new task to replace it. This process continues until your service reaches your desired number of tasks based on the scheduling strategy that the service uses. The scheduling strategy of the service is also referred to as the service type.

The service scheduler includes logic that throttles how often tasks are restarted if tasks repeatedly fail to start. If a task is stopped without having entered a RUNNING state, the service scheduler starts to slow down the launch attempts and sends out a service event message. This behavior prevents unnecessary resources from being used for failed tasks before you can resolve the issue. After the service is updated, the service scheduler resumes normal scheduling behavior. For more information, see Service throttle logic and Service event messages.

There are two service scheduler strategies available:

  • REPLICA—The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions. For more information, see Replica.

  • DAEMON—The daemon scheduling strategy deploys exactly one task on each active container instance that meets all of the task placement constraints that you specify in your cluster. The service scheduler evaluates the task placement constraints for running tasks and will stop tasks that do not meet the placement constraints. When using this strategy, there is no need to specify a desired number of tasks, a task placement strategy, or use Service Auto Scaling policies. For more information, see Daemon in the Amazon Elastic Container Service Developer Guide.

    Note

    Fargate tasks do not support the DAEMON scheduling strategy.

Replica

The replica scheduling strategy places and maintains the desired number of tasks in your cluster.

For a service that runs tasks on Fargate, when the service scheduler launches new tasks or stops running tasks, the service scheduler attempts to maintain a balance across Availability Zones. You don't need to specify task placement strategies or restraints.

Additional service concepts

  • You can optionally run your service behind a load balancer. For more information, see Service load balancing.

  • You can optionally specify a deployment configuration for your service. A deployment is triggered by updating the task definition or desired count of a service. During a deployment, the service scheduler uses the minimum healthy percent and maximum percent parameters to determine the deployment strategy. For more information, see Service definition parameters.

  • You can optionally configure your service to use Amazon ECS service discovery. Service discovery uses the AWS Cloud Map autonaming APIs to manage DNS entries for your service's tasks. This makes them discoverable from within your VPC. For more information, see Service Discovery.

  • When you delete a service, if there are still running tasks that require cleanup, the service moves from an ACTIVE to a DRAINING status, and the service is no longer visible in the console or in the ListServices API operation. After all tasks have transitioned to either a STOPPING or STOPPED status, the service moves from a DRAINING to INACTIVE status. You can view services in the DRAINING or INACTIVE status by using the DescribeServices API operation. However, in the future, INACTIVE services might be cleaned up and purged from Amazon ECS record keeping, and DescribeServices calls on those services return a ServiceNotFoundException error.