AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Starts a new task using the specified task definition.

On March 21, 2024, a change was made to resolve the task definition revision before authorization. When a task definition revision is not specified, authorization will occur using the latest revision of a task definition.

Amazon Elastic Inference (EI) is no longer available to customers.

You can allow Amazon ECS to place tasks for you, or you can customize how Amazon ECS places tasks using placement constraints and placement strategies. For more information, see Scheduling Tasks in the Amazon Elastic Container Service Developer Guide.

Alternatively, you can use StartTask to use your own scheduler or place tasks manually on specific container instances.

You can attach Amazon EBS volumes to Amazon ECS tasks by configuring the volume when creating or updating a service. For more information, see Amazon EBS volumes in the Amazon Elastic Container Service Developer Guide.

The Amazon ECS API follows an eventual consistency model. This is because of the distributed nature of the system supporting the API. This means that the result of an API command you run that affects your Amazon ECS resources might not be immediately visible to all subsequent commands you run. Keep this in mind when you carry out an API command that immediately follows a previous API command.

To manage eventual consistency, you can do the following:

If you get a ConflictException error, the RunTask request could not be processed due to conflicts. The provided clientToken is already in use with a different RunTask request. The resourceIds are the existing task ARNs which are already associated with the clientToken.

To fix this issue:

If you get a ClientExceptionerror, the RunTask could not be processed because you use managed scaling and there is a capacity error because the quota of tasks in the PROVISIONING per cluster has been reached. For information about the service quotas, see Amazon ECS service quotas.

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to RunTaskAsync.

Namespace: Amazon.ECS
Assembly: AWSSDK.ECS.dll
Version: 3.x.y.z

Syntax

C#
public virtual RunTaskResponse RunTask(
         RunTaskRequest request
)

Parameters

request
Type: Amazon.ECS.Model.RunTaskRequest

Container for the necessary parameters to execute the RunTask service method.

Return Value


The response from the RunTask service method, as returned by ECS.

Exceptions

ExceptionCondition
AccessDeniedException You don't have authorization to perform the requested action.
BlockedException Your Amazon Web Services account was blocked. For more information, contact Amazon Web Services Support.
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.
ConflictException The request could not be processed because of conflict in the current state of the resource.
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.
PlatformTaskDefinitionIncompatibilityException The specified platform version doesn't satisfy the required capabilities of the task definition.
PlatformUnknownException The specified platform version doesn't exist.
ServerException These errors are usually caused by a server issue.
UnsupportedFeatureException The specified task isn't supported in this Region.

Examples

This example runs the specified task definition on your default cluster.

To run a task on your default cluster


var client = new AmazonECSClient();
var response = client.RunTask(new RunTaskRequest 
{
    Cluster = "default",
    TaskDefinition = "sleep360:1"
});

List<Task> tasks = response.Tasks;

            

Version Information

.NET Framework:
Supported in: 4.5 and newer, 3.5

See Also