Running an application as an Amazon ECS task
You can create a task for a one-time process using the Amazon Web Services Management Console.
To create a standalone task (Amazon Web Services Management Console)
Open the console at https://console.amazonaws.cn/ecs/v2
. -
The Amazon ECS console allows you to create a standalone task from either your cluster detail page or from the task definition revision list. Use the following steps to create your standalone task depending on the resource page you choose.
To start a service from Steps a cluster detail page...
-
On the Clusters page, select the cluster to create the service in.
-
From the Tasks tab, choose Run new task.
a task definition revision page... -
On the Task definitions page, choose the task definition family to display the revisions for that family.
-
Select the revision you want to use.
-
From the Deploy menu, choose Run task.
-
-
(Optional) The Compute configuration (advanced) section is where you choose how your tasks will be distributed. You can use either a Capacity provider strategy or a Launch type. To use a capacity provider strategy, you must configure your capacity providers at the cluster level. If you haven't configured your cluster to use a capacity provider, use a launch type instead.
Distribution method Steps Capacity provider strategy
-
In the Compute options section, select Capacity provider strategy.
-
Choose a strategy:
-
To use the cluster's default capacity provider strategy, choose Use cluster default.
-
If your cluster doesn't have a default capacity provider strategy, or to use a custom strategy, choose Use custom, Add capacity provider strategy and define your custom capacity provider strategy by specifying a Base, Capacity provider, and Weight.
-
Note
To use a capacity provider in a strategy, the capacity provider must be associated with the cluster.
Launch type -
In the Compute options section, select Launch type.
-
For Launch type, choose a launch type.
-
(Optional) When the Fargate launch type is specified, for Platform version, specify the platform version to use. If a platform version isn't specified, the
LATEST
platform version is used.
-
-
For Application type, choose Task.
-
For Task definition, choose the task definition family and revision.
Important
The console validates the selection to ensure that the selected task definition family and revision are compatible with the defined compute configuration.
-
For Desired tasks, enter the number of tasks to launch.
-
If your task definition uses the
awsvpc
network mode, expand Networking. Use the following steps to specify a custom configuration.-
For VPC, select the VPC to use.
-
For Subnets, select one or more subnets in the VPC that the task scheduler considers when placing your tasks.
Important
Only private subnets are supported for the
awsvpc
network mode. Tasks do not receive public IP addresses. Therefore, a NAT gateway is required for outbound internet access, and inbound internet traffic is routed through a load balancer. -
For Security group, you can either choose an existing security group or create a new one. To use an existing security group, choose the security group and move to the next step. To create a new security group, choose Create a new security group. You must specify a security group name, description, and then add one or more inbound rules for the security group.
-
For Public IP, choose whether to auto-assign a public IP address to the elastic network interface (ENI) of the task.
Amazon Fargate tasks can be assigned a public IP address when run in a public subnet so they have a route to the internet. EC2 tasks can't be assigned a public IP using this field. For more information, see Amazon ECS task networking options for the Fargate launch type and Allocate a network interface for an Amazon ECS task..
-
-
(Optional) To use a task placement strategy other than the default, expand Task Placement, and then choose from the following options.
For more information, see How Amazon ECS places tasks on container instances.
-
AZ Balanced Spread – Distribute tasks across Availability Zones and across container instances in the Availability Zone.
-
AZ Balanced BinPack – Distribute tasks across Availability Zones and across container instances with the least available memory.
-
BinPack – Distribute tasks based on the least available amount of CPU or memory.
-
One Task Per Host – Place, at most, one task from the service on each container instance.
-
Custom – Define your own task placement strategy.
If you chose Custom, define the algorithm for placing tasks and the rules that are considered during task placement.
-
Under Strategy, for Type and Field, choose the algorithm and the entity to use for the algorithm.
You can enter a maximum of 5 strategies.
-
Under Constraint, for Type and Expression, choose the rule and attribute for the constraint.
For example, to set the constraint to place tasks on T2 instances, for the Expression, enter attribute:ecs.instance-type =~ t2.*.
You can enter a maximum of 10 constraints.
-
-
(Optional) To override the task IAM role, or task execution role that is defined in your task definition, expand Task overrides, and then complete the following steps:
-
For Task role, choose an IAM role for this task. For more information, see Amazon ECS task IAM role.
Only roles with the
ecs-tasks.amazonaws.com
trust relationship are displayed. For instructions on how to create an IAM role for your tasks, see Creating the task IAM role. -
For Task execution role, choose a task execution role. For more information, see Amazon ECS task execution IAM role.
-
-
(Optional) To override the container commands and environment variables, expand Container Overrides, and then expand the container.
-
To send a command to the container other than the task definition command, for Command override, enter the Docker command.
-
To add an environment variable, choose Add Environment Variable. For Key, enter the name of your environment variable. For Value, enter a string value for your environment value (without the surrounding double quotation marks (
" "
)).Amazon surrounds the strings with double quotation marks (" ") and passes the string to the container in the following format:
MY_ENV_VAR="This variable contains a string."
-
-
(Optional) To help identify your task, expand the Tags section, and then configure your tags.
To have Amazon ECS automatically tag all newly launched tasks with the cluster name and the task definition tags, select Turn on Amazon ECS managed tags, and then select Task definitions.
Add or remove a tag.
-
[Add a tag] Choose Add tag, and then do the following:
-
For Key, enter the key name.
-
For Value, enter the key value.
-
-
[Remove a tag] Next to the tag, choose Remove tag.
-
-
Choose Create.