Amazon EC2 Container Service

2016/08/11 - Amazon EC2 Container Service - 4 updated api methods

Changes  Update ecs client to latest version

CreateService (updated) Link ¶
Changes (request, response)
Request
{'loadBalancers': {'targetGroupArn': 'string'}}
Response
{'service': {'loadBalancers': {'targetGroupArn': 'string'}}}

Runs and maintains a desired number of tasks from a specified task definition. If the number of tasks running in a service drops below desiredCount, Amazon ECS spawns another instantiation of the task in the specified cluster. To update an existing service, see UpdateService.

In addition to maintaining the desired count of tasks in your service, you can optionally run your service behind a load balancer. The load balancer distributes traffic across the tasks that are associated with the service. For more information, see Service Load Balancing in the Amazon EC2 Container Service Developer Guide.

You can optionally specify a deployment configuration for your service. During a deployment (which is triggered by changing the task definition of a service with an UpdateService operation), the service scheduler uses the minimumHealthyPercent and maximumPercent parameters to determine the deployment strategy.

If the minimumHealthyPercent is below 100%, the scheduler can ignore the desiredCount temporarily during a deployment. For example, if your service has a desiredCount of four tasks, a minimumHealthyPercent of 50% allows the scheduler to stop two existing tasks before starting two new tasks. Tasks for services that do not use a load balancer are considered healthy if they are in the RUNNING state; tasks for services that do use a load balancer are considered healthy if they are in the RUNNING state and the container instance it is hosted on is reported as healthy by the load balancer. The default value for minimumHealthyPercent is 50% in the console and 100% for the AWS CLI, the AWS SDKs, and the APIs.

The maximumPercent parameter represents an upper limit on the number of running tasks during a deployment, which enables you to define the deployment batch size. For example, if your service has a desiredCount of four tasks, a maximumPercent value of 200% starts four new tasks before stopping the four older tasks (provided that the cluster resources required to do this are available). The default value for maximumPercent is 200%.

When the service scheduler launches new tasks, it attempts to balance them across the Availability Zones in your cluster with the following logic:

  • Determine which of the container instances in your cluster can support your service's task definition (for example, they have the required CPU, memory, ports, and container instance attributes).

  • Sort the valid container instances by the fewest number of running tasks for this service in the same Availability Zone as the instance. For example, if zone A has one running service task and zones B and C each have zero, valid container instances in either zone B or C are considered optimal for placement.

  • Place the new service task on a valid container instance in an optimal Availability Zone (based on the previous steps), favoring container instances with the fewest number of running tasks for this service.

Request Syntax

client.create_service(
    cluster='string',
    serviceName='string',
    taskDefinition='string',
    loadBalancers=[
        {
            'targetGroupArn': 'string',
            'loadBalancerName': 'string',
            'containerName': 'string',
            'containerPort': 123
        },
    ],
    desiredCount=123,
    clientToken='string',
    role='string',
    deploymentConfiguration={
        'maximumPercent': 123,
        'minimumHealthyPercent': 123
    }
)
type cluster:

string

param cluster:

The short name or full Amazon Resource Name (ARN) of the cluster on which to run your service. If you do not specify a cluster, the default cluster is assumed.

type serviceName:

string

param serviceName:

[REQUIRED]

The name of your service. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed. Service names must be unique within a cluster, but you can have similarly named services in multiple clusters within a region or across multiple regions.

type taskDefinition:

string

param taskDefinition:

[REQUIRED]

The family and revision ( family:revision) or full Amazon Resource Name (ARN) of the task definition to run in your service. If a revision is not specified, the latest ACTIVE revision is used.

type loadBalancers:

list

param loadBalancers:

A load balancer object representing the load balancer to use with your service. Currently, you are limited to one load balancer per service. After you create a service, the load balancer name, container name, and container port specified in the service definition are immutable.

For Elastic Load Balancing Classic load balancers, this object must contain the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer. When a task from this service is placed on a container instance, the container instance is registered with the load balancer specified here.

For Elastic Load Balancing Application load balancers, this object must contain the load balancer target group ARN, the container name (as it appears in a container definition), and the container port to access from the load balancer. When a task from this service is placed on a container instance, the container instance and port combination is registered as a target in the target group specified here.

  • (dict) --

    Details on a load balancer that is used with a service.

    • targetGroupArn (string) --

      The full Amazon Resource Name (ARN) of the Elastic Load Balancing target group associated with a service.

    • loadBalancerName (string) --

      The name of the load balancer.

    • containerName (string) --

      The name of the container (as it appears in a container definition) to associate with the load balancer.

    • containerPort (integer) --

      The port on the container to associate with the load balancer. This port must correspond to a containerPort in the service's task definition. Your container instances must allow ingress traffic on the hostPort of the port mapping.

type desiredCount:

integer

param desiredCount:

[REQUIRED]

The number of instantiations of the specified task definition to place and keep running on your cluster.

type clientToken:

string

param clientToken:

Unique, case-sensitive identifier you provide to ensure the idempotency of the request. Up to 32 ASCII characters are allowed.

type role:

string

param role:

The name or full Amazon Resource Name (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. If you specify the role parameter, you must also specify a load balancer object with the loadBalancers parameter.

If your specified role has a path other than /, then you must either specify the full role ARN (this is recommended) or prefix the role name with the path. For example, if a role with the name bar has a path of /foo/ then you would specify /foo/bar as the role name. For more information, see Friendly Names and Paths in the IAM User Guide.

type deploymentConfiguration:

dict

param deploymentConfiguration:

Optional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.

  • maximumPercent (integer) --

    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. The maximum number of tasks during a deployment is the desiredCount multiplied by the maximumPercent/100, rounded down to the nearest integer value.

  • minimumHealthyPercent (integer) --

    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. The minimum healthy tasks during a deployment is the desiredCount multiplied by the minimumHealthyPercent/100, rounded up to the nearest integer value.

rtype:

dict

returns:

Response Syntax

{
    'service': {
        'serviceArn': 'string',
        'serviceName': 'string',
        'clusterArn': 'string',
        'loadBalancers': [
            {
                'targetGroupArn': 'string',
                'loadBalancerName': 'string',
                'containerName': 'string',
                'containerPort': 123
            },
        ],
        'status': 'string',
        'desiredCount': 123,
        'runningCount': 123,
        'pendingCount': 123,
        'taskDefinition': 'string',
        'deploymentConfiguration': {
            'maximumPercent': 123,
            'minimumHealthyPercent': 123
        },
        'deployments': [
            {
                'id': 'string',
                'status': 'string',
                'taskDefinition': 'string',
                'desiredCount': 123,
                'pendingCount': 123,
                'runningCount': 123,
                'createdAt': datetime(2015, 1, 1),
                'updatedAt': datetime(2015, 1, 1)
            },
        ],
        'roleArn': 'string',
        'events': [
            {
                'id': 'string',
                'createdAt': datetime(2015, 1, 1),
                'message': 'string'
            },
        ],
        'createdAt': datetime(2015, 1, 1)
    }
}

Response Structure

  • (dict) --

    • service (dict) --

      The full description of your service following the create call.

      • serviceArn (string) --

        The Amazon Resource Name (ARN) that identifies the service. The ARN contains the arn:aws:ecs namespace, followed by the region of the service, the AWS account ID of the service owner, the service namespace, and then the service name. For example, ``arn:aws:ecs:region:012345678910:service/my-service ``.

      • serviceName (string) --

        The name of your service. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed. Service names must be unique within a cluster, but you can have similarly named services in multiple clusters within a region or across multiple regions.

      • clusterArn (string) --

        The Amazon Resource Name (ARN) of the cluster that hosts the service.

      • loadBalancers (list) --

        A list of Elastic Load Balancing load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer.

        • (dict) --

          Details on a load balancer that is used with a service.

          • targetGroupArn (string) --

            The full Amazon Resource Name (ARN) of the Elastic Load Balancing target group associated with a service.

          • loadBalancerName (string) --

            The name of the load balancer.

          • containerName (string) --

            The name of the container (as it appears in a container definition) to associate with the load balancer.

          • containerPort (integer) --

            The port on the container to associate with the load balancer. This port must correspond to a containerPort in the service's task definition. Your container instances must allow ingress traffic on the hostPort of the port mapping.

      • status (string) --

        The status of the service. The valid values are ACTIVE, DRAINING, or INACTIVE.

      • desiredCount (integer) --

        The desired number of instantiations of the task definition to keep running on the service. This value is specified when the service is created with CreateService, and it can be modified with UpdateService.

      • runningCount (integer) --

        The number of tasks in the cluster that are in the RUNNING state.

      • pendingCount (integer) --

        The number of tasks in the cluster that are in the PENDING state.

      • taskDefinition (string) --

        The task definition to use for tasks in the service. This value is specified when the service is created with CreateService, and it can be modified with UpdateService.

      • deploymentConfiguration (dict) --

        Optional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.

        • maximumPercent (integer) --

          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. The maximum number of tasks during a deployment is the desiredCount multiplied by the maximumPercent/100, rounded down to the nearest integer value.

        • minimumHealthyPercent (integer) --

          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. The minimum healthy tasks during a deployment is the desiredCount multiplied by the minimumHealthyPercent/100, rounded up to the nearest integer value.

      • deployments (list) --

        The current state of deployments for the service.

        • (dict) --

          The details of an Amazon ECS service deployment.

          • id (string) --

            The ID of the deployment.

          • status (string) --

            The status of the deployment. Valid values are PRIMARY (for the most recent deployment), ACTIVE (for previous deployments that still have tasks running, but are being replaced with the PRIMARY deployment), and INACTIVE (for deployments that have been completely replaced).

          • taskDefinition (string) --

            The most recent task definition that was specified for the service to use.

          • desiredCount (integer) --

            The most recent desired count of tasks that was specified for the service to deploy or maintain.

          • pendingCount (integer) --

            The number of tasks in the deployment that are in the PENDING status.

          • runningCount (integer) --

            The number of tasks in the deployment that are in the RUNNING status.

          • createdAt (datetime) --

            The Unix timestamp for when the service was created.

          • updatedAt (datetime) --

            The Unix timestamp for when the service was last updated.

      • roleArn (string) --

        The Amazon Resource Name (ARN) of the IAM role associated with the service that allows the Amazon ECS container agent to register container instances with an Elastic Load Balancing load balancer.

      • events (list) --

        The event stream for your service. A maximum of 100 of the latest events are displayed.

        • (dict) --

          Details on an event associated with a service.

          • id (string) --

            The ID string of the event.

          • createdAt (datetime) --

            The Unix timestamp for when the event was triggered.

          • message (string) --

            The event message.

      • createdAt (datetime) --

        The Unix timestamp for when the service was created.

DeleteService (updated) Link ¶
Changes (response)
{'service': {'loadBalancers': {'targetGroupArn': 'string'}}}

Deletes a specified service within a cluster. You can delete a service if you have no running tasks in it and the desired task count is zero. If the service is actively maintaining tasks, you cannot delete it, and you must update the service to a desired task count of zero. For more information, see UpdateService.

Request Syntax

client.delete_service(
    cluster='string',
    service='string'
)
type cluster:

string

param cluster:

The name of the cluster that hosts the service to delete. If you do not specify a cluster, the default cluster is assumed.

type service:

string

param service:

[REQUIRED]

The name of the service to delete.

rtype:

dict

returns:

Response Syntax

{
    'service': {
        'serviceArn': 'string',
        'serviceName': 'string',
        'clusterArn': 'string',
        'loadBalancers': [
            {
                'targetGroupArn': 'string',
                'loadBalancerName': 'string',
                'containerName': 'string',
                'containerPort': 123
            },
        ],
        'status': 'string',
        'desiredCount': 123,
        'runningCount': 123,
        'pendingCount': 123,
        'taskDefinition': 'string',
        'deploymentConfiguration': {
            'maximumPercent': 123,
            'minimumHealthyPercent': 123
        },
        'deployments': [
            {
                'id': 'string',
                'status': 'string',
                'taskDefinition': 'string',
                'desiredCount': 123,
                'pendingCount': 123,
                'runningCount': 123,
                'createdAt': datetime(2015, 1, 1),
                'updatedAt': datetime(2015, 1, 1)
            },
        ],
        'roleArn': 'string',
        'events': [
            {
                'id': 'string',
                'createdAt': datetime(2015, 1, 1),
                'message': 'string'
            },
        ],
        'createdAt': datetime(2015, 1, 1)
    }
}

Response Structure

  • (dict) --

    • service (dict) --

      The full description of the deleted service.

      • serviceArn (string) --

        The Amazon Resource Name (ARN) that identifies the service. The ARN contains the arn:aws:ecs namespace, followed by the region of the service, the AWS account ID of the service owner, the service namespace, and then the service name. For example, ``arn:aws:ecs:region:012345678910:service/my-service ``.

      • serviceName (string) --

        The name of your service. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed. Service names must be unique within a cluster, but you can have similarly named services in multiple clusters within a region or across multiple regions.

      • clusterArn (string) --

        The Amazon Resource Name (ARN) of the cluster that hosts the service.

      • loadBalancers (list) --

        A list of Elastic Load Balancing load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer.

        • (dict) --

          Details on a load balancer that is used with a service.

          • targetGroupArn (string) --

            The full Amazon Resource Name (ARN) of the Elastic Load Balancing target group associated with a service.

          • loadBalancerName (string) --

            The name of the load balancer.

          • containerName (string) --

            The name of the container (as it appears in a container definition) to associate with the load balancer.

          • containerPort (integer) --

            The port on the container to associate with the load balancer. This port must correspond to a containerPort in the service's task definition. Your container instances must allow ingress traffic on the hostPort of the port mapping.

      • status (string) --

        The status of the service. The valid values are ACTIVE, DRAINING, or INACTIVE.

      • desiredCount (integer) --

        The desired number of instantiations of the task definition to keep running on the service. This value is specified when the service is created with CreateService, and it can be modified with UpdateService.

      • runningCount (integer) --

        The number of tasks in the cluster that are in the RUNNING state.

      • pendingCount (integer) --

        The number of tasks in the cluster that are in the PENDING state.

      • taskDefinition (string) --

        The task definition to use for tasks in the service. This value is specified when the service is created with CreateService, and it can be modified with UpdateService.

      • deploymentConfiguration (dict) --

        Optional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.

        • maximumPercent (integer) --

          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. The maximum number of tasks during a deployment is the desiredCount multiplied by the maximumPercent/100, rounded down to the nearest integer value.

        • minimumHealthyPercent (integer) --

          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. The minimum healthy tasks during a deployment is the desiredCount multiplied by the minimumHealthyPercent/100, rounded up to the nearest integer value.

      • deployments (list) --

        The current state of deployments for the service.

        • (dict) --

          The details of an Amazon ECS service deployment.

          • id (string) --

            The ID of the deployment.

          • status (string) --

            The status of the deployment. Valid values are PRIMARY (for the most recent deployment), ACTIVE (for previous deployments that still have tasks running, but are being replaced with the PRIMARY deployment), and INACTIVE (for deployments that have been completely replaced).

          • taskDefinition (string) --

            The most recent task definition that was specified for the service to use.

          • desiredCount (integer) --

            The most recent desired count of tasks that was specified for the service to deploy or maintain.

          • pendingCount (integer) --

            The number of tasks in the deployment that are in the PENDING status.

          • runningCount (integer) --

            The number of tasks in the deployment that are in the RUNNING status.

          • createdAt (datetime) --

            The Unix timestamp for when the service was created.

          • updatedAt (datetime) --

            The Unix timestamp for when the service was last updated.

      • roleArn (string) --

        The Amazon Resource Name (ARN) of the IAM role associated with the service that allows the Amazon ECS container agent to register container instances with an Elastic Load Balancing load balancer.

      • events (list) --

        The event stream for your service. A maximum of 100 of the latest events are displayed.

        • (dict) --

          Details on an event associated with a service.

          • id (string) --

            The ID string of the event.

          • createdAt (datetime) --

            The Unix timestamp for when the event was triggered.

          • message (string) --

            The event message.

      • createdAt (datetime) --

        The Unix timestamp for when the service was created.

DescribeServices (updated) Link ¶
Changes (response)
{'services': {'loadBalancers': {'targetGroupArn': 'string'}}}

Describes the specified services running in your cluster.

Request Syntax

client.describe_services(
    cluster='string',
    services=[
        'string',
    ]
)
type cluster:

string

param cluster:

The name of the cluster that hosts the service to describe. If you do not specify a cluster, the default cluster is assumed.

type services:

list

param services:

[REQUIRED]

A list of services to describe.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'services': [
        {
            'serviceArn': 'string',
            'serviceName': 'string',
            'clusterArn': 'string',
            'loadBalancers': [
                {
                    'targetGroupArn': 'string',
                    'loadBalancerName': 'string',
                    'containerName': 'string',
                    'containerPort': 123
                },
            ],
            'status': 'string',
            'desiredCount': 123,
            'runningCount': 123,
            'pendingCount': 123,
            'taskDefinition': 'string',
            'deploymentConfiguration': {
                'maximumPercent': 123,
                'minimumHealthyPercent': 123
            },
            'deployments': [
                {
                    'id': 'string',
                    'status': 'string',
                    'taskDefinition': 'string',
                    'desiredCount': 123,
                    'pendingCount': 123,
                    'runningCount': 123,
                    'createdAt': datetime(2015, 1, 1),
                    'updatedAt': datetime(2015, 1, 1)
                },
            ],
            'roleArn': 'string',
            'events': [
                {
                    'id': 'string',
                    'createdAt': datetime(2015, 1, 1),
                    'message': 'string'
                },
            ],
            'createdAt': datetime(2015, 1, 1)
        },
    ],
    'failures': [
        {
            'arn': 'string',
            'reason': 'string'
        },
    ]
}

Response Structure

  • (dict) --

    • services (list) --

      The list of services described.

      • (dict) --

        Details on a service within a cluster

        • serviceArn (string) --

          The Amazon Resource Name (ARN) that identifies the service. The ARN contains the arn:aws:ecs namespace, followed by the region of the service, the AWS account ID of the service owner, the service namespace, and then the service name. For example, ``arn:aws:ecs:region:012345678910:service/my-service ``.

        • serviceName (string) --

          The name of your service. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed. Service names must be unique within a cluster, but you can have similarly named services in multiple clusters within a region or across multiple regions.

        • clusterArn (string) --

          The Amazon Resource Name (ARN) of the cluster that hosts the service.

        • loadBalancers (list) --

          A list of Elastic Load Balancing load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer.

          • (dict) --

            Details on a load balancer that is used with a service.

            • targetGroupArn (string) --

              The full Amazon Resource Name (ARN) of the Elastic Load Balancing target group associated with a service.

            • loadBalancerName (string) --

              The name of the load balancer.

            • containerName (string) --

              The name of the container (as it appears in a container definition) to associate with the load balancer.

            • containerPort (integer) --

              The port on the container to associate with the load balancer. This port must correspond to a containerPort in the service's task definition. Your container instances must allow ingress traffic on the hostPort of the port mapping.

        • status (string) --

          The status of the service. The valid values are ACTIVE, DRAINING, or INACTIVE.

        • desiredCount (integer) --

          The desired number of instantiations of the task definition to keep running on the service. This value is specified when the service is created with CreateService, and it can be modified with UpdateService.

        • runningCount (integer) --

          The number of tasks in the cluster that are in the RUNNING state.

        • pendingCount (integer) --

          The number of tasks in the cluster that are in the PENDING state.

        • taskDefinition (string) --

          The task definition to use for tasks in the service. This value is specified when the service is created with CreateService, and it can be modified with UpdateService.

        • deploymentConfiguration (dict) --

          Optional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.

          • maximumPercent (integer) --

            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. The maximum number of tasks during a deployment is the desiredCount multiplied by the maximumPercent/100, rounded down to the nearest integer value.

          • minimumHealthyPercent (integer) --

            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. The minimum healthy tasks during a deployment is the desiredCount multiplied by the minimumHealthyPercent/100, rounded up to the nearest integer value.

        • deployments (list) --

          The current state of deployments for the service.

          • (dict) --

            The details of an Amazon ECS service deployment.

            • id (string) --

              The ID of the deployment.

            • status (string) --

              The status of the deployment. Valid values are PRIMARY (for the most recent deployment), ACTIVE (for previous deployments that still have tasks running, but are being replaced with the PRIMARY deployment), and INACTIVE (for deployments that have been completely replaced).

            • taskDefinition (string) --

              The most recent task definition that was specified for the service to use.

            • desiredCount (integer) --

              The most recent desired count of tasks that was specified for the service to deploy or maintain.

            • pendingCount (integer) --

              The number of tasks in the deployment that are in the PENDING status.

            • runningCount (integer) --

              The number of tasks in the deployment that are in the RUNNING status.

            • createdAt (datetime) --

              The Unix timestamp for when the service was created.

            • updatedAt (datetime) --

              The Unix timestamp for when the service was last updated.

        • roleArn (string) --

          The Amazon Resource Name (ARN) of the IAM role associated with the service that allows the Amazon ECS container agent to register container instances with an Elastic Load Balancing load balancer.

        • events (list) --

          The event stream for your service. A maximum of 100 of the latest events are displayed.

          • (dict) --

            Details on an event associated with a service.

            • id (string) --

              The ID string of the event.

            • createdAt (datetime) --

              The Unix timestamp for when the event was triggered.

            • message (string) --

              The event message.

        • createdAt (datetime) --

          The Unix timestamp for when the service was created.

    • failures (list) --

      Any failures associated with the call.

      • (dict) --

        A failed resource.

        • arn (string) --

          The Amazon Resource Name (ARN) of the failed resource.

        • reason (string) --

          The reason for the failure.

UpdateService (updated) Link ¶
Changes (response)
{'service': {'loadBalancers': {'targetGroupArn': 'string'}}}

Modifies the desired count, deployment configuration, or task definition used in a service.

You can add to or subtract from the number of instantiations of a task definition in a service by specifying the cluster that the service is running in and a new desiredCount parameter.

You can use UpdateService to modify your task definition and deploy a new version of your service.

You can also update the deployment configuration of a service. When a deployment is triggered by updating the task definition of a service, the service scheduler uses the deployment configuration parameters, minimumHealthyPercent and maximumPercent, to determine the deployment strategy.

If the minimumHealthyPercent is below 100%, the scheduler can ignore the desiredCount temporarily during a deployment. For example, if your service has a desiredCount of four tasks, a minimumHealthyPercent of 50% allows the scheduler to stop two existing tasks before starting two new tasks. Tasks for services that do not use a load balancer are considered healthy if they are in the RUNNING state; tasks for services that do use a load balancer are considered healthy if they are in the RUNNING state and the container instance it is hosted on is reported as healthy by the load balancer.

The maximumPercent parameter represents an upper limit on the number of running tasks during a deployment, which enables you to define the deployment batch size. For example, if your service has a desiredCount of four tasks, a maximumPercent value of 200% starts four new tasks before stopping the four older tasks (provided that the cluster resources required to do this are available).

When UpdateService stops a task during a deployment, the equivalent of docker stop is issued to the containers running in the task. This results in a SIGTERM and a 30-second timeout, after which SIGKILL is sent and the containers are forcibly stopped. If the container handles the SIGTERM gracefully and exits within 30 seconds from receiving it, no SIGKILL is sent.

When the service scheduler launches new tasks, it attempts to balance them across the Availability Zones in your cluster with the following logic:

  • Determine which of the container instances in your cluster can support your service's task definition (for example, they have the required CPU, memory, ports, and container instance attributes).

  • Sort the valid container instances by the fewest number of running tasks for this service in the same Availability Zone as the instance. For example, if zone A has one running service task and zones B and C each have zero, valid container instances in either zone B or C are considered optimal for placement.

  • Place the new service task on a valid container instance in an optimal Availability Zone (based on the previous steps), favoring container instances with the fewest number of running tasks for this service.

Request Syntax

client.update_service(
    cluster='string',
    service='string',
    desiredCount=123,
    taskDefinition='string',
    deploymentConfiguration={
        'maximumPercent': 123,
        'minimumHealthyPercent': 123
    }
)
type cluster:

string

param cluster:

The short name or full Amazon Resource Name (ARN) of the cluster that your service is running on. If you do not specify a cluster, the default cluster is assumed.

type service:

string

param service:

[REQUIRED]

The name of the service to update.

type desiredCount:

integer

param desiredCount:

The number of instantiations of the task to place and keep running in your service.

type taskDefinition:

string

param taskDefinition:

The family and revision ( family:revision) or full Amazon Resource Name (ARN) of the task definition to run in your service. If a revision is not specified, the latest ACTIVE revision is used. If you modify the task definition with UpdateService, Amazon ECS spawns a task with the new version of the task definition and then stops an old task after the new version is running.

type deploymentConfiguration:

dict

param deploymentConfiguration:

Optional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.

  • maximumPercent (integer) --

    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. The maximum number of tasks during a deployment is the desiredCount multiplied by the maximumPercent/100, rounded down to the nearest integer value.

  • minimumHealthyPercent (integer) --

    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. The minimum healthy tasks during a deployment is the desiredCount multiplied by the minimumHealthyPercent/100, rounded up to the nearest integer value.

rtype:

dict

returns:

Response Syntax

{
    'service': {
        'serviceArn': 'string',
        'serviceName': 'string',
        'clusterArn': 'string',
        'loadBalancers': [
            {
                'targetGroupArn': 'string',
                'loadBalancerName': 'string',
                'containerName': 'string',
                'containerPort': 123
            },
        ],
        'status': 'string',
        'desiredCount': 123,
        'runningCount': 123,
        'pendingCount': 123,
        'taskDefinition': 'string',
        'deploymentConfiguration': {
            'maximumPercent': 123,
            'minimumHealthyPercent': 123
        },
        'deployments': [
            {
                'id': 'string',
                'status': 'string',
                'taskDefinition': 'string',
                'desiredCount': 123,
                'pendingCount': 123,
                'runningCount': 123,
                'createdAt': datetime(2015, 1, 1),
                'updatedAt': datetime(2015, 1, 1)
            },
        ],
        'roleArn': 'string',
        'events': [
            {
                'id': 'string',
                'createdAt': datetime(2015, 1, 1),
                'message': 'string'
            },
        ],
        'createdAt': datetime(2015, 1, 1)
    }
}

Response Structure

  • (dict) --

    • service (dict) --

      The full description of your service following the update call.

      • serviceArn (string) --

        The Amazon Resource Name (ARN) that identifies the service. The ARN contains the arn:aws:ecs namespace, followed by the region of the service, the AWS account ID of the service owner, the service namespace, and then the service name. For example, ``arn:aws:ecs:region:012345678910:service/my-service ``.

      • serviceName (string) --

        The name of your service. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed. Service names must be unique within a cluster, but you can have similarly named services in multiple clusters within a region or across multiple regions.

      • clusterArn (string) --

        The Amazon Resource Name (ARN) of the cluster that hosts the service.

      • loadBalancers (list) --

        A list of Elastic Load Balancing load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer.

        • (dict) --

          Details on a load balancer that is used with a service.

          • targetGroupArn (string) --

            The full Amazon Resource Name (ARN) of the Elastic Load Balancing target group associated with a service.

          • loadBalancerName (string) --

            The name of the load balancer.

          • containerName (string) --

            The name of the container (as it appears in a container definition) to associate with the load balancer.

          • containerPort (integer) --

            The port on the container to associate with the load balancer. This port must correspond to a containerPort in the service's task definition. Your container instances must allow ingress traffic on the hostPort of the port mapping.

      • status (string) --

        The status of the service. The valid values are ACTIVE, DRAINING, or INACTIVE.

      • desiredCount (integer) --

        The desired number of instantiations of the task definition to keep running on the service. This value is specified when the service is created with CreateService, and it can be modified with UpdateService.

      • runningCount (integer) --

        The number of tasks in the cluster that are in the RUNNING state.

      • pendingCount (integer) --

        The number of tasks in the cluster that are in the PENDING state.

      • taskDefinition (string) --

        The task definition to use for tasks in the service. This value is specified when the service is created with CreateService, and it can be modified with UpdateService.

      • deploymentConfiguration (dict) --

        Optional deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks.

        • maximumPercent (integer) --

          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. The maximum number of tasks during a deployment is the desiredCount multiplied by the maximumPercent/100, rounded down to the nearest integer value.

        • minimumHealthyPercent (integer) --

          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. The minimum healthy tasks during a deployment is the desiredCount multiplied by the minimumHealthyPercent/100, rounded up to the nearest integer value.

      • deployments (list) --

        The current state of deployments for the service.

        • (dict) --

          The details of an Amazon ECS service deployment.

          • id (string) --

            The ID of the deployment.

          • status (string) --

            The status of the deployment. Valid values are PRIMARY (for the most recent deployment), ACTIVE (for previous deployments that still have tasks running, but are being replaced with the PRIMARY deployment), and INACTIVE (for deployments that have been completely replaced).

          • taskDefinition (string) --

            The most recent task definition that was specified for the service to use.

          • desiredCount (integer) --

            The most recent desired count of tasks that was specified for the service to deploy or maintain.

          • pendingCount (integer) --

            The number of tasks in the deployment that are in the PENDING status.

          • runningCount (integer) --

            The number of tasks in the deployment that are in the RUNNING status.

          • createdAt (datetime) --

            The Unix timestamp for when the service was created.

          • updatedAt (datetime) --

            The Unix timestamp for when the service was last updated.

      • roleArn (string) --

        The Amazon Resource Name (ARN) of the IAM role associated with the service that allows the Amazon ECS container agent to register container instances with an Elastic Load Balancing load balancer.

      • events (list) --

        The event stream for your service. A maximum of 100 of the latest events are displayed.

        • (dict) --

          Details on an event associated with a service.

          • id (string) --

            The ID string of the event.

          • createdAt (datetime) --

            The Unix timestamp for when the event was triggered.

          • message (string) --

            The event message.

      • createdAt (datetime) --

        The Unix timestamp for when the service was created.