listTasks method

Future<ListTasksResponse> listTasks({
  1. String? cluster,
  2. String? containerInstance,
  3. DesiredStatus? desiredStatus,
  4. String? family,
  5. LaunchType? launchType,
  6. int? maxResults,
  7. String? nextToken,
  8. String? serviceName,
  9. String? startedBy,
})

Returns a list of tasks for a specified cluster. You can filter the results by family name, by a particular container instance, or by the desired status of the task with the family, containerInstance, and desiredStatus parameters.

Recently stopped tasks might appear in the returned results. Currently, stopped tasks appear in the returned results for at least one hour.

May throw ServerException. May throw ClientException. May throw InvalidParameterException. May throw ClusterNotFoundException. May throw ServiceNotFoundException.

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

Parameter containerInstance : The container instance ID or full ARN of the container instance with which to filter the ListTasks results. Specifying a containerInstance limits the results to tasks that belong to that container instance.

Parameter desiredStatus : The task desired status with which to filter 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 are not 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.

Parameter family : The name of the family with which to filter the ListTasks results. Specifying a family limits the results to tasks that belong to that family.

Parameter launchType : The launch type for services to list.

Parameter maxResults : The maximum number of task results returned by ListTasks 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 is not used, then ListTasks returns up to 100 results and a nextToken value if applicable.

Parameter nextToken : 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 is possible the number of results to be fewer than maxResults.

Parameter serviceName : The name of the service with which to filter the ListTasks results. Specifying a serviceName limits the results to tasks that belong to that service.

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

Implementation

Future<ListTasksResponse> listTasks({
  String? cluster,
  String? containerInstance,
  DesiredStatus? desiredStatus,
  String? family,
  LaunchType? launchType,
  int? maxResults,
  String? nextToken,
  String? serviceName,
  String? startedBy,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AmazonEC2ContainerServiceV20141113.ListTasks'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      if (cluster != null) 'cluster': cluster,
      if (containerInstance != null) 'containerInstance': containerInstance,
      if (desiredStatus != null) 'desiredStatus': desiredStatus.toValue(),
      if (family != null) 'family': family,
      if (launchType != null) 'launchType': launchType.toValue(),
      if (maxResults != null) 'maxResults': maxResults,
      if (nextToken != null) 'nextToken': nextToken,
      if (serviceName != null) 'serviceName': serviceName,
      if (startedBy != null) 'startedBy': startedBy,
    },
  );

  return ListTasksResponse.fromJson(jsonResponse.body);
}