Skip to content

list_container_instances

list_container_instances(
    *,
    config_overrides: Optional[ECSClientConfig] = None,
    cluster: Optional[String] = None,
    filter: Optional[String] = None,
    next_token: Optional[String] = None,
    max_results: Optional[BoxedInteger] = None,
    status: Optional[ContainerInstanceStatus] = None,
) -> ListContainerInstancesResponse

Returns a list of container instances in a specified cluster. You can filter the results of a ListContainerInstances operation with cluster query language statements inside the filter parameter. For more information, see Cluster Query Language in the Amazon Elastic Container Service Developer Guide.

Parameters:

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

    The short name or full Amazon Resource Name (ARN) of the cluster that hosts the container instances to list. If you do not specify a cluster, the default cluster is assumed.

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

    You can filter the results of a ListContainerInstances operation with cluster query language statements. For more information, see Cluster Query Language in the Amazon Elastic Container Service Developer Guide.

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

    The nextToken value returned from a ListContainerInstances request indicating that more results are available to fulfill the request and further calls are 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 container instance results that ListContainerInstances returned in paginated output. When this parameter is used, ListContainerInstances 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 ListContainerInstances request with the returned nextToken value. This value can be between 1 and 100. If this parameter isn't used, then ListContainerInstances returns up to 100 results and a nextToken value if applicable.

  • status (Optional[ContainerInstanceStatus], default: None ) –

    Filters the container instances by status. For example, if you specify the DRAINING status, the results include only container instances that have been set to DRAINING using UpdateContainerInstancesState. If you don't specify this parameter, the The default is to include container instances set to all states other than INACTIVE.

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.

  • UnknownServiceError –

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

Examples:

To list your available container instances in a cluster This example lists all of your available container instances in the specified cluster in your default region.

>>> client.list_container_instances(cluster='default')
Source code in docs_src/capo_ecs/_services/ecs.py
def list_container_instances(
    self,
    *,
    config_overrides: Optional[ECSClientConfig] = None,
    cluster: Optional["capo_ecs.types.string.String"] = None,
    filter: 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,
    status: Optional[
        "capo_ecs.types.container_instance_status.ContainerInstanceStatus"
    ] = None,
) -> "capo_ecs.types.list_container_instances_response.ListContainerInstancesResponse":
    """<p>Returns a list of container instances in a specified cluster. You can filter the results of a <code>ListContainerInstances</code> operation with cluster query language statements inside the <code>filter</code> parameter. For more information, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html">Cluster Query Language</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>

    Args:
        cluster: <p>The short name or full Amazon Resource Name (ARN) of the cluster that hosts the container instances to list. If you do not specify a cluster, the default cluster is assumed.</p>
        filter: <p>You can filter the results of a <code>ListContainerInstances</code> operation with cluster query language statements. For more information, see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html">Cluster Query Language</a> in the <i>Amazon Elastic Container Service Developer Guide</i>.</p>
        next_token: <p>The <code>nextToken</code> value returned from a <code>ListContainerInstances</code> request indicating that more results are available to fulfill the request and further calls are 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 container instance results that <code>ListContainerInstances</code> returned in paginated output. When this parameter is used, <code>ListContainerInstances</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>ListContainerInstances</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>ListContainerInstances</code> returns up to 100 results and a <code>nextToken</code> value if applicable.</p>
        status: <p>Filters the container instances by status. For example, if you specify the <code>DRAINING</code> status, the results include only container instances that have been set to <code>DRAINING</code> using <a href="https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateContainerInstancesState.html">UpdateContainerInstancesState</a>. If you don't specify this parameter, the The default is to include container instances set to all states other than <code>INACTIVE</code>.</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.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To list your available container instances in a cluster
        This example lists all of your available container instances in the specified cluster in your default region.

        >>> client.list_container_instances(cluster='default')
    """

    def _handler(
        req: "OperationRequest[capo_ecs.types.list_container_instances_request.ListContainerInstancesRequest]",
    ) -> OperationResponse[
        "capo_ecs.types.list_container_instances_response.ListContainerInstancesResponse"
    ]:
        import capo_ecs._operations.amazon_ec2_container_service_v20141113.list_container_instances

        output, http_response = (
            capo_ecs._operations.amazon_ec2_container_service_v20141113.list_container_instances.list_container_instances(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ListContainerInstances")
    )
    input_: capo_ecs.types.list_container_instances_request.ListContainerInstancesRequest = {}
    if cluster is not None:
        input_["cluster"] = cluster
    if filter is not None:
        input_["filter"] = filter
    if next_token is not None:
        input_["next_token"] = next_token
    if max_results is not None:
        input_["max_results"] = max_results
    if status is not None:
        input_["status"] = status

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output