- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
ListTasksCommand
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.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { ECSClient, ListTasksCommand } from "@aws-sdk/client-ecs"; // ES Modules import
// const { ECSClient, ListTasksCommand } = require("@aws-sdk/client-ecs"); // CommonJS import
const client = new ECSClient(config);
const input = { // ListTasksRequest
cluster: "STRING_VALUE",
containerInstance: "STRING_VALUE",
family: "STRING_VALUE",
nextToken: "STRING_VALUE",
maxResults: Number("int"),
startedBy: "STRING_VALUE",
serviceName: "STRING_VALUE",
desiredStatus: "RUNNING" || "PENDING" || "STOPPED",
launchType: "EC2" || "FARGATE" || "EXTERNAL",
};
const command = new ListTasksCommand(input);
const response = await client.send(command);
// { // ListTasksResponse
// taskArns: [ // StringList
// "STRING_VALUE",
// ],
// nextToken: "STRING_VALUE",
// };
Example Usage
ListTasksCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
cluster | string | undefined | The short name or full Amazon Resource Name (ARN) of the cluster to use when filtering the |
containerInstance | string | undefined | The container instance ID or full ARN of the container instance to use when filtering the |
desiredStatus | DesiredStatus | undefined | The task desired status to use when filtering the Although you can filter results based on a desired status of |
family | string | undefined | The name of the task definition family to use when filtering the |
launchType | LaunchType | undefined | The launch type to use when filtering the |
maxResults | number | undefined | The maximum number of task results that |
nextToken | string | undefined | The 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. |
serviceName | string | undefined | The name of the service to use when filtering the |
startedBy | string | undefined | The When you specify |
ListTasksCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
nextToken | string | undefined | The |
taskArns | string[] | undefined | The list of task ARN entries for the |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
ClientException | client | 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 | client | The specified cluster wasn't found. You can view your available clusters with ListClusters . Amazon ECS clusters are Region specific. |
InvalidParameterException | client | 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 | server | These errors are usually caused by a server issue. |
ServiceNotFoundException | client | The specified service wasn't found. You can view your available services with ListServices . Amazon ECS services are cluster specific and Region specific. |
ECSServiceException | Base exception class for all service exceptions from ECS service. |