run-task — AWS CLI 2.1.29 Command Reference
Description
Starts a new task using the specified 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.
The Amazon ECS API follows an eventual consistency model, due to 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:
Confirm the state of the resource before you run a command to modify it. Run the DescribeTasks command using an exponential backoff algorithm to ensure that you allow enough time for the previous command to propagate through the system. To do this, run the DescribeTasks command repeatedly, starting with a couple of seconds of wait time and increasing gradually up to five minutes of wait time.
Add wait time between subsequent commands, even if the DescribeTasks command returns an accurate response. Apply an exponential backoff algorithm starting with a couple of seconds of wait time, and increase gradually up to about five minutes of wait time.
See also: AWS API Documentation
See ‘aws help’ for descriptions of global parameters.
Options
--capacity-provider-strategy (list)
The capacity provider strategy to use for the task.
A capacity provider strategy consists of one or more capacity providers along with the
baseandweightto assign to them. A capacity provider must be associated with the cluster to be used in a capacity provider strategy. The PutClusterCapacityProviders API is used to associate a capacity provider with a cluster. Only capacity providers with anACTIVEorUPDATINGstatus can be used.If a
capacityProviderStrategyis specified, thelaunchTypeparameter must be omitted. If nocapacityProviderStrategyorlaunchTypeis specified, thedefaultCapacityProviderStrategyfor the cluster is used.If specifying a capacity provider that uses an Auto Scaling group, the capacity provider must already be created. New capacity providers can be created with the CreateCapacityProvider API operation.
To use a AWS Fargate capacity provider, specify either the
FARGATEorFARGATE_SPOTcapacity providers. The AWS Fargate capacity providers are available to all accounts and only need to be associated with a cluster to be used.The PutClusterCapacityProviders API operation is used to update the list of available capacity providers for a cluster after the cluster is created.
(structure)
The details of a capacity provider strategy.
capacityProvider -> (string)
The short name of the capacity provider.
weight -> (integer)
The weight value designates the relative percentage of the total number of tasks launched that should use the specified capacity provider.
For example, if you have a strategy that contains two capacity providers and both have a weight of
1, then when thebaseis satisfied, the tasks will be split evenly across the two capacity providers. Using that same logic, if you specify a weight of1for capacityProviderA and a weight of4for capacityProviderB , then for every one task that is run using capacityProviderA , four tasks would use capacityProviderB .base -> (integer)
The base value designates how many tasks, at a minimum, to run on the specified capacity provider. Only one capacity provider in a capacity provider strategy can have a base defined.
Shorthand Syntax:
capacityProvider=string,weight=integer,base=integer ...
JSON Syntax:
[ { "capacityProvider": "string", "weight": integer, "base": integer } ...]
--cluster (string)
The short name or full Amazon Resource Name (ARN) of the cluster on which to run your task. If you do not specify a cluster, the default cluster is assumed.
--count (integer)
The number of instantiations of the specified task to place on your cluster. You can specify up to 10 tasks per call.
--enable-ecs-managed-tags | --no-enable-ecs-managed-tags (boolean)
Specifies whether to enable Amazon ECS managed tags for the task. For more information, see Tagging Your Amazon ECS Resources in the Amazon Elastic Container Service Developer Guide .
--group (string)
The name of the task group to associate with the task. The default value is the family name of the task definition (for example, family:my-family-name).
--launch-type (string)
The launch type on which to run your task. For more information, see Amazon ECS Launch Types in the Amazon Elastic Container Service Developer Guide .
If a
launchTypeis specified, thecapacityProviderStrategyparameter must be omitted.Possible values:
EC2
FARGATE
--network-configuration (structure)
The network configuration for the task. This parameter is required for task definitions that use the
awsvpcnetwork mode to receive their own elastic network interface, and it is not supported for other network modes. For more information, see Task Networking in the Amazon Elastic Container Service Developer Guide .awsvpcConfiguration -> (structure)
The VPC subnets and security groups associated with a task.
Note
All specified subnets and security groups must be from the same VPC.
subnets -> (list)
The IDs of the subnets associated with the task or service. There is a limit of 16 subnets that can be specified per
AwsVpcConfiguration.Note
All specified subnets must be from the same VPC.
(string)
securityGroups -> (list)
The IDs of the security groups associated with the task or service. If you do not specify a security group, the default security group for the VPC is used. There is a limit of 5 security groups that can be specified per
AwsVpcConfiguration.Note
All specified security groups must be from the same VPC.
(string)
assignPublicIp -> (string)
Whether the task’s elastic network interface receives a public IP address. The default value is
DISABLED.
Shorthand Syntax:
awsvpcConfiguration={subnets=[string,string],securityGroups=[string,string],assignPublicIp=string}
JSON Syntax:
{ "awsvpcConfiguration": { "subnets": ["string", ...], "securityGroups": ["string", ...], "assignPublicIp": "ENABLED"|"DISABLED" }}
--overrides (structure)
A list of container overrides in JSON format that specify the name of a container in the specified task definition and the overrides it should receive. You can override the default command for a container (that is specified in the task definition or Docker image) with a
commandoverride. You can also override existing environment variables (that are specified in the task definition or Docker image) on a container or add new environment variables to it with anenvironmentoverride.Note
A total of 8192 characters are allowed for overrides. This limit includes the JSON formatting characters of the override structure.
containerOverrides -> (list)
One or more container overrides sent to a task.
(structure)
The overrides that should be sent to a container. An empty container override can be passed in. An example of an empty container override would be
{"containerOverrides": [ ] }. If a non-empty container override is specified, thenameparameter must be included.name -> (string)
The name of the container that receives the override. This parameter is required if any override is specified.
command -> (list)
The command to send to the container that overrides the default command from the Docker image or the task definition. You must also specify a container name.
(string)
environment -> (list)
The environment variables to send to the container. You can add new environment variables, which are added to the container at launch, or you can override the existing environment variables from the Docker image or the task definition. You must also specify a container name.
(structure)
A key-value pair object.
name -> (string)
The name of the key-value pair. For environment variables, this is the name of the environment variable.
value -> (string)
The value of the key-value pair. For environment variables, this is the value of the environment variable.
environmentFiles -> (list)
A list of files containing the environment variables to pass to a container, instead of the value from the container definition.
(structure)
A list of files containing the environment variables to pass to a container. You can specify up to ten environment files. The file must have a
.envfile extension. Each line in an environment file should contain an environment variable inVARIABLE=VALUEformat. Lines beginning with#are treated as comments and are ignored. For more information on the environment variable file syntax, see Declare default environment variables in file .If there are environment variables specified using the
environmentparameter in a container definition, they take precedence over the variables contained within an environment file. If multiple environment files are specified that contain the same variable, they are processed from the top down. It is recommended to use unique variable names. For more information, see Specifying Environment Variables in the Amazon Elastic Container Service Developer Guide .This field is not valid for containers in tasks using the Fargate launch type.
value -> (string)
The Amazon Resource Name (ARN) of the Amazon S3 object containing the environment variable file.
type -> (string)
The file type to use. The only supported value is
s3.cpu -> (integer)
The number of
cpuunits reserved for the container, instead of the default value from the task definition. You must also specify a container name.memory -> (integer)
The hard limit (in MiB) of memory to present to the container, instead of the default value from the task definition. If your container attempts to exceed the memory specified here, the container is killed. You must also specify a container name.
memoryReservation -> (integer)
The soft limit (in MiB) of memory to reserve for the container, instead of the default value from the task definition. You must also specify a container name.
resourceRequirements -> (list)
The type and amount of a resource to assign to a container, instead of the default value from the task definition. The only supported resource is a GPU.
(structure)
The type and amount of a resource to assign to a container. The supported resource types are GPUs and Elastic Inference accelerators. For more information, see Working with GPUs on Amazon ECS or Working with Amazon Elastic Inference on Amazon ECS in the Amazon Elastic Container Service Developer Guide
value -> (string)
The value for the specified resource type.
If the
GPUtype is used, the value is the number of physicalGPUsthe Amazon ECS container agent will reserve for the container. The number of GPUs reserved for all containers in a task should not exceed the number of available GPUs on the container instance the task is launched on.If the
InferenceAcceleratortype is used, thevalueshould match thedeviceNamefor an InferenceAccelerator specified in a task definition.type -> (string)
The type of resource to assign to a container. The supported values are
GPUorInferenceAccelerator.cpu -> (string)
The cpu override for the task.
inferenceAcceleratorOverrides -> (list)
The Elastic Inference accelerator override for the task.
(structure)
Details on an Elastic Inference accelerator task override. This parameter is used to override the Elastic Inference accelerator specified in the task definition. For more information, see Working with Amazon Elastic Inference on Amazon ECS in the Amazon Elastic Container Service Developer Guide .
deviceName -> (string)
The Elastic Inference accelerator device name to override for the task. This parameter must match a
deviceNamespecified in the task definition.deviceType -> (string)
The Elastic Inference accelerator type to use.
executionRoleArn -> (string)
The Amazon Resource Name (ARN) of the task execution IAM role override for the task.
memory -> (string)
The memory override for the task.
taskRoleArn -> (string)
The Amazon Resource Name (ARN) of the IAM role that containers in this task can assume. All containers in this task are granted the permissions that are specified in this role.
JSON Syntax:
{ "containerOverrides": [ { "name": "string", "command": ["string", ...], "environment": [ { "name": "string", "value": "string" } ... ], "environmentFiles": [ { "value": "string", "type": "s3" } ... ], "cpu": integer, "memory": integer, "memoryReservation": integer, "resourceRequirements": [ { "value": "string", "type": "GPU"|"InferenceAccelerator" } ... ] } ... ], "cpu": "string", "inferenceAcceleratorOverrides": [ { "deviceName": "string", "deviceType": "string" } ... ], "executionRoleArn": "string", "memory": "string", "taskRoleArn": "string"}
--placement-constraints (list)
An array of placement constraint objects to use for the task. You can specify up to 10 constraints per task (including constraints in the task definition and those specified at runtime).
(structure)
An object representing a constraint on task placement. For more information, see Task Placement Constraints in the Amazon Elastic Container Service Developer Guide .
Note
If you are using the Fargate launch type, task placement constraints are not supported.
type -> (string)
The type of constraint. Use
distinctInstanceto ensure that each task in a particular group is running on a different container instance. UsememberOfto restrict the selection to a group of valid candidates.expression -> (string)
A cluster query language expression to apply to the constraint. You cannot specify an expression if the constraint type is
distinctInstance. For more information, see Cluster Query Language in the Amazon Elastic Container Service Developer Guide .
Shorthand Syntax:
type=string,expression=string ...
JSON Syntax:
[ { "type": "distinctInstance"|"memberOf", "expression": "string" } ...]
--placement-strategy (list)
The placement strategy objects to use for the task. You can specify a maximum of five strategy rules per task.
(structure)
The task placement strategy for a task or service. For more information, see Task Placement Strategies in the Amazon Elastic Container Service Developer Guide .
type -> (string)
The type of placement strategy. The
randomplacement strategy randomly places tasks on available candidates. Thespreadplacement strategy spreads placement across available candidates evenly based on thefieldparameter. Thebinpackstrategy places tasks on available candidates that have the least available amount of the resource that is specified with thefieldparameter. For example, if you binpack on memory, a task is placed on the instance with the least amount of remaining memory (but still enough to run the task).field -> (string)
The field to apply the placement strategy against. For the
spreadplacement strategy, valid values areinstanceId(orhost, which has the same effect), or any platform or custom attribute that is applied to a container instance, such asattribute:ecs.availability-zone. For thebinpackplacement strategy, valid values arecpuandmemory. For therandomplacement strategy, this field is not used.
Shorthand Syntax:
type=string,field=string ...
JSON Syntax:
[ { "type": "random"|"spread"|"binpack", "field": "string" } ...]
--platform-version (string)
The platform version the task should run. A platform version is only specified for tasks using the Fargate launch type. If one is not specified, the
LATESTplatform version is used by default. For more information, see AWS Fargate Platform Versions in the Amazon Elastic Container Service Developer Guide .
--propagate-tags (string)
Specifies whether to propagate the tags from the task definition to the task. If no value is specified, the tags are not propagated. Tags can only be propagated to the task during task creation. To add tags to a task after task creation, use the TagResource API action.
Note
An error will be received if you specify the
SERVICEoption when running a task.Possible values:
TASK_DEFINITION
SERVICE
--reference-id (string)
The reference ID to use for the task.
--started-by (string)
An optional tag specified when a task is started. For example, if you automatically trigger a task to run a batch process job, you could apply a unique identifier for that job to your task with the
startedByparameter. You can then identify which tasks belong to that job by filtering the results of a ListTasks call with thestartedByvalue. Up to 36 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed.If a task is started by an Amazon ECS service, then the
startedByparameter contains the deployment ID of the service that starts it.
--tags (list)
The metadata that you apply to the task to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define.
The following basic restrictions apply to tags:
Maximum number of tags per resource - 50
For each resource, each tag key must be unique, and each tag key can have only one value.
Maximum key length - 128 Unicode characters in UTF-8
Maximum value length - 256 Unicode characters in UTF-8
If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.
Tag keys and values are case-sensitive.
Do not use
aws:,AWS:, or any upper or lowercase combination of such as a prefix for either keys or values as it is reserved for AWS use. You cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource limit.(structure)
The metadata that you apply to a resource to help you categorize and organize them. Each tag consists of a key and an optional value, both of which you define.
The following basic restrictions apply to tags:
Maximum number of tags per resource - 50
For each resource, each tag key must be unique, and each tag key can have only one value.
Maximum key length - 128 Unicode characters in UTF-8
Maximum value length - 256 Unicode characters in UTF-8
If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.
Tag keys and values are case-sensitive.
Do not use
aws:,AWS:, or any upper or lowercase combination of such as a prefix for either keys or values as it is reserved for AWS use. You cannot edit or delete tag keys or values with this prefix. Tags with this prefix do not count against your tags per resource limit.key -> (string)
One part of a key-value pair that make up a tag. A
keyis a general label that acts like a category for more specific tag values.value -> (string)
The optional part of a key-value pair that make up a tag. A
valueacts as a descriptor within a tag category (key).
Shorthand Syntax:
key=string,value=string ...
JSON Syntax:
[ { "key": "string", "value": "string" } ...]
--task-definition (string)
The
familyandrevision(family:revision) or full ARN of the task definition to run. If arevisionis not specified, the latestACTIVErevision is used.
--cli-input-json | --cli-input-yaml (string)
Reads arguments from the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton. If other arguments are provided on the command line, those values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally. This may not be specified along with --cli-input-yaml.
--generate-cli-skeleton (string)
Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. Similarly, if provided yaml-input it will print a sample input YAML that can be used with --cli-input-yaml. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.
See ‘aws help’ for descriptions of global parameters.
Examples
To run a task on your default cluster
The following run-task example runs a task on the default cluster.
aws ecs run-task --cluster default --task-definition sleep360:1
Output:
{ "tasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-ccdef-11111EXAMPLE", "overrides": { "containerOverrides": [ { "name": "sleep" } ] }, "lastStatus": "PENDING", "containerInstanceArn": "arn:aws:ecs:us-west-2:123456789012:container-instance/a1b2c3d4-5678-90ab-ccdef-22222EXAMPLE", "desiredStatus": "RUNNING", "taskDefinitionArn": "arn:aws:ecs:us-west-2:123456789012:task-definition/sleep360:1", "containers": [ { "containerArn": "arn:aws:ecs:us-west-2:123456789012:container/a1b2c3d4-5678-90ab-ccdef-33333EXAMPLE", "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-ccdef-11111EXAMPLE", "lastStatus": "PENDING", "name": "sleep" } ] } ]}
For more information, see Running Tasks in the Amazon ECS Developer Guide.