Skip to content

list_tasks async

list_tasks(
    *,
    config_overrides: Optional[AsyncECSClientConfig] = None,
    cluster: Optional[String] = None,
    container_instance: Optional[String] = None,
    family: Optional[String] = None,
    next_token: Optional[String] = None,
    max_results: Optional[BoxedInteger] = None,
    started_by: Optional[String] = None,
    service_name: Optional[String] = None,
    desired_status: Optional[DesiredStatus] = None,
    launch_type: Optional[LaunchType] = None,
    daemon_name: Optional[String] = None,
) -> ListTasksResponse

Returns a list of tasks. You can filter the results by cluster, task definition family, container instance, launch type, what IAM principal started the task, or by the desired status of the task.

Recently stopped tasks might appear in the returned results.

Parameters:

  • cluster (Optional[String], default: None ) –

    The short name or full Amazon Resource Name (ARN) of the cluster to use when filtering the ListTasks results. If you do not specify a cluster, the default cluster is assumed.

  • container_instance (Optional[String], default: None ) –

    The container instance ID or full ARN of the container instance to use when filtering the ListTasks results. Specifying a containerInstance limits the results to tasks that belong to that container instance.

  • family (Optional[String], default: None ) –

    The name of the task definition family to use when filtering the ListTasks results. Specifying a family limits the results to tasks that belong to that family.

  • next_token (Optional[String], default: None ) –

    The nextToken value returned from a ListTasks request indicating that more results are available to fulfill the request and further calls will be needed. If maxResults was provided, it's possible the number of results to be fewer than maxResults.

    This token should be treated as an opaque identifier that is only used to retrieve the next items in a list and not for other programmatic purposes.

  • max_results (Optional[BoxedInteger], default: None ) –

    The maximum number of task results that ListTasks returned in paginated output. When this parameter is used, ListTasks only returns maxResults results in a single page along with a nextToken response element. The remaining results of the initial request can be seen by sending another ListTasks request with the returned nextToken value. This value can be between 1 and 100. If this parameter isn't used, then ListTasks returns up to 100 results and a nextToken value if applicable.

  • started_by (Optional[String], default: None ) –

    The startedBy value to filter the task results with. Specifying a startedBy value limits the results to tasks that were started with that value.

    When you specify startedBy as the filter, it must be the only filter that you use.

  • service_name (Optional[String], default: None ) –

    The name of the service to use when filtering the ListTasks results. Specifying a serviceName limits the results to tasks that belong to that service.

  • desired_status (Optional[DesiredStatus], default: None ) –

    The task desired status to use when filtering the ListTasks results. Specifying a desiredStatus of STOPPED limits the results to tasks that Amazon ECS has set the desired status to STOPPED. This can be useful for debugging tasks that aren't starting properly or have died or finished. The default status filter is RUNNING, which shows tasks that Amazon ECS has set the desired status to RUNNING.

    Although you can filter results based on a desired status of PENDING, this doesn't return any results. Amazon ECS never sets the desired status of a task to that value (only a task's lastStatus may have a value of PENDING).

  • launch_type (Optional[LaunchType], default: None ) –

    The launch type to use when filtering the ListTasks results.

  • daemon_name (Optional[String], default: None ) –

    The name of the daemon to use when filtering the ListTasks results. Specifying a daemonName limits the results to tasks that belong to that daemon.

Raises:

  • AccessDeniedException –

    You don't have authorization to perform the requested action.

  • ClientException –

    These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Or, it might be specifying an identifier that isn't valid.

  • ClusterNotFoundException –

    The specified cluster wasn't found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region specific.

  • InvalidParameterException –

    The specified parameter isn't valid. Review the available parameters for the API request.

    For more information about service event errors, see Amazon ECS service event messages.

  • ServerException –

    These errors are usually caused by a server issue.

  • ServiceNotFoundException –

    The specified service wasn't found. You can view your available services with ListServices. Amazon ECS services are cluster specific and Region specific.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To list the tasks in a cluster This example lists all of the tasks in a cluster.

>>> await client.list_tasks(cluster='default')
To list the tasks on a particular container instance
This example lists the tasks of a specified container instance. Specifying a ``containerInstance`` value limits  the  results  to  tasks  that belong to that container instance.
>>> await client.list_tasks(cluster='default', container_instance='f6bbb147-5370-4ace-8c73-c7181ded911f')
Source code in docs_src/capo_ecs/_services/async_ecs.py
async def list_tasks(
    self,
    *,
    config_overrides: Optional[AsyncECSClientConfig] = None,
    cluster: Optional["capo_ecs.types.string.String"] = None,
    container_instance: Optional["capo_ecs.types.string.String"] = None,
    family: Optional["capo_ecs.types.string.String"] = None,
    next_token: Optional["capo_ecs.types.string.String"] = None,
    max_results: Optional["capo_ecs.types.boxed_integer.BoxedInteger"] = None,
    started_by: Optional["capo_ecs.types.string.String"] = None,
    service_name: Optional["capo_ecs.types.string.String"] = None,
    desired_status: Optional["capo_ecs.types.desired_status.DesiredStatus"] = None,
    launch_type: Optional["capo_ecs.types.launch_type.LaunchType"] = None,
    daemon_name: Optional["capo_ecs.types.string.String"] = None,
) -> "capo_ecs.types.list_tasks_response.ListTasksResponse":
    """<p>Returns a list of tasks. You can filter the results by cluster, task definition family, container instance, launch type, what IAM principal started the task, or by the desired status of the task.</p> <p>Recently stopped tasks might appear in the returned results. </p>

    Args:
        cluster: <p>The short name or full Amazon Resource Name (ARN) of the cluster to use when filtering the <code>ListTasks</code> results. If you do not specify a cluster, the default cluster is assumed.</p>
        container_instance: <p>The container instance ID or full ARN of the container instance to use when filtering the <code>ListTasks</code> results. Specifying a <code>containerInstance</code> limits the results to tasks that belong to that container instance.</p>
        family: <p>The name of the task definition family to use when filtering the <code>ListTasks</code> results. Specifying a <code>family</code> limits the results to tasks that belong to that family.</p>
        next_token: <p>The <code>nextToken</code> value returned from a <code>ListTasks</code> request indicating that more results are available to fulfill the request and further calls will be needed. If <code>maxResults</code> was provided, it's possible the number of results to be fewer than <code>maxResults</code>.</p> <note> <p>This token should be treated as an opaque identifier that is only used to retrieve the next items in a list and not for other programmatic purposes.</p> </note>
        max_results: <p>The maximum number of task results that <code>ListTasks</code> returned in paginated output. When this parameter is used, <code>ListTasks</code> only returns <code>maxResults</code> results in a single page along with a <code>nextToken</code> response element. The remaining results of the initial request can be seen by sending another <code>ListTasks</code> request with the returned <code>nextToken</code> value. This value can be between 1 and 100. If this parameter isn't used, then <code>ListTasks</code> returns up to 100 results and a <code>nextToken</code> value if applicable.</p>
        started_by: <p>The <code>startedBy</code> value to filter the task results with. Specifying a <code>startedBy</code> value limits the results to tasks that were started with that value.</p> <p>When you specify <code>startedBy</code> as the filter, it must be the only filter that you use.</p>
        service_name: <p>The name of the service to use when filtering the <code>ListTasks</code> results. Specifying a <code>serviceName</code> limits the results to tasks that belong to that service.</p>
        desired_status: <p>The task desired status to use when filtering the <code>ListTasks</code> results. Specifying a <code>desiredStatus</code> of <code>STOPPED</code> limits the results to tasks that Amazon ECS has set the desired status to <code>STOPPED</code>. This can be useful for debugging tasks that aren't starting properly or have died or finished. The default status filter is <code>RUNNING</code>, which shows tasks that Amazon ECS has set the desired status to <code>RUNNING</code>.</p> <note> <p>Although you can filter results based on a desired status of <code>PENDING</code>, this doesn't return any results. Amazon ECS never sets the desired status of a task to that value (only a task's <code>lastStatus</code> may have a value of <code>PENDING</code>).</p> </note>
        launch_type: <p>The launch type to use when filtering the <code>ListTasks</code> results.</p>
        daemon_name: <p>The name of the daemon to use when filtering the <code>ListTasks</code> results. Specifying a <code>daemonName</code> limits the results to tasks that belong to that daemon.</p>

    Raises:
        capo_ecs.errors.access_denied_exception.AccessDeniedException: <p>You don't have authorization to perform the requested action.</p>
        capo_ecs.errors.client_exception.ClientException: <p>These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Or, it might be specifying an identifier that isn't valid.</p>
        capo_ecs.errors.cluster_not_found_exception.ClusterNotFoundException: <p>The specified cluster wasn't found. You can view your available clusters with <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListClusters.html">ListClusters</a>. Amazon ECS clusters are Region specific.</p>
        capo_ecs.errors.invalid_parameter_exception.InvalidParameterException: <p>The specified parameter isn't valid. Review the available parameters for the API request.</p> <p>For more information about service event errors, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-event-messages-list.html">Amazon ECS service event messages</a>. </p>
        capo_ecs.errors.server_exception.ServerException: <p>These errors are usually caused by a server issue.</p>
        capo_ecs.errors.service_not_found_exception.ServiceNotFoundException: <p>The specified service wasn't found. You can view your available services with <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListServices.html">ListServices</a>. Amazon ECS services are cluster specific and Region specific.</p>
        capo_ecs.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To list the tasks in a cluster
        This example lists all of the tasks in a cluster.

        >>> await client.list_tasks(cluster='default')
        To list the tasks on a particular container instance
        This example lists the tasks of a specified container instance. Specifying a ``containerInstance`` value limits  the  results  to  tasks  that belong to that container instance.

        >>> await client.list_tasks(cluster='default', container_instance='f6bbb147-5370-4ace-8c73-c7181ded911f')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ecs.types.list_tasks_request.ListTasksRequest]",
    ) -> AsyncOperationResponse[
        "capo_ecs.types.list_tasks_response.ListTasksResponse"
    ]:
        import capo_ecs._operations.amazon_ec2_container_service_v20141113.list_tasks

        (
            output,
            http_response,
        ) = await capo_ecs._operations.amazon_ec2_container_service_v20141113.list_tasks.async_list_tasks(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ListTasks")
    )
    input_: capo_ecs.types.list_tasks_request.ListTasksRequest = {}
    if cluster is not None:
        input_["cluster"] = cluster
    if container_instance is not None:
        input_["container_instance"] = container_instance
    if family is not None:
        input_["family"] = family
    if next_token is not None:
        input_["next_token"] = next_token
    if max_results is not None:
        input_["max_results"] = max_results
    if started_by is not None:
        input_["started_by"] = started_by
    if service_name is not None:
        input_["service_name"] = service_name
    if desired_status is not None:
        input_["desired_status"] = desired_status
    if launch_type is not None:
        input_["launch_type"] = launch_type
    if daemon_name is not None:
        input_["daemon_name"] = daemon_name

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output