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.

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.

Starting April 15, 2023, Amazon Web Services will not onboard new customers to Amazon Elastic Inference (EI), and will help current customers migrate their workloads to options that offer better price and performance. After April 15, 2023, new customers will not be able to launch instances with Amazon EI accelerators in Amazon SageMaker, Amazon ECS, or Amazon EC2. However, customers who have used Amazon EI at least once during the past 30-day period are considered current customers and will be able to continue using the service.

You can attach Amazon EBS volumes to Amazon ECS tasks by configuring the volume when creating or updating a service. For more infomation, 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:

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 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: Run RunTask with a unique clientToken. Run RunTask with the clientToken and the original set of parameters
InvalidParameterException The specified parameter isn't valid. Review the available parameters for the API request.
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, 4.0, 3.5

See Also