Running a standalone task using the Amazon ECS console - Amazon Elastic Container Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Running a standalone task using the Amazon ECS console

We recommend that you deploy your application as a standalone task in some situations. For example, suppose that you're developing an application but you're not ready to deploy it with the service scheduler. If your application is a one-time or periodic batch job, it doesn't make sense to keep running or restart when it finishes.

To deploy your application to run continually or to place it behind a load balancer, create an Amazon ECS service. For more information, see Amazon ECS services.

To run a standalone task use one of the following procedures.

Consider the following when you use the new console;

  • Task definitions that use the awsvpc network mode or services configured to use a load balancer must have a networking configuration. By default, the console selects the default Amazon VPC along with all subnets and the default security group within the default Amazon VPC.

  • For the EC2 launch type, the default task placement strategy is to distribute the tasks across Availability Zones and across container instances in the Availability Zone.

  • For the capacity provider strategy, the console selects a compute option by default. The following describes the order that the console uses to select a default:

    • If your cluster has a default capacity provider strategy defined, it is selected.

    • If your cluster doesn't have a default capacity provider strategy defined but you do have the Fargate capacity providers added to the cluster, a custom capacity provider strategy that uses the FARGATE capacity provider is selected.

    • If your cluster doesn't have a default capacity provider strategy defined but you do have one or more Auto Scaling group capacity providers added to the cluster, the Use custom (Advanced) option is selected and you need to manually define the strategy.

    • If your cluster doesn't have a default capacity provider strategy defined and no capacity providers added to the cluster, the Fargate launch type is selected.

To run a task from the console
  1. Open the console at https://console.amazonaws.cn/ecs/v2.

  2. Determine the resource from where you launch the service.

    To start a service from Steps

    Clusters

    1. On the Clusters page, select the cluster to create the service in.

    2. From the Tasks tab, choose Run new task.

    Launch type
    1. On the Task page, choose the task definition.

    2. If there is more than one revision, select the revision.

    3. Choose Create, Run task.

  3. (Optional) Choose how your scheduled task is distributed across your cluster infrastructure. Expand Compute configuration, and then do the following:

    Distribution method Steps

    Capacity provider strategy

    1. In the Compute options section, select Capacity provider strategy.

    2. 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. For more information about capacity provider strategies, see Amazon ECS capacity providers.

    Launch type
    1. In the Compute options section, select Launch type.

    2. For Launch type, choose a launch type.

    3. (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 by default.

  4. For Application type, choose Task.

  5. For Task definition, choose the task definition family and revision to use.

    Important

    The console validates the selection to ensure that the selected task definition family and revision is compatible with the defined compute configuration.

  6. For Desired tasks, enter the number of tasks to launch.

  7. If your task definition uses the awsvpc network mode, expand Networking. Use the following steps to specify a custom configuration.

    1. For VPC, select the VPC to use.

    2. 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.

    3. For Security group, you can either select an existing security group or create a new one. To use an existing security group, select 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.

    4. 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. For more information, see Fargate task networking in the Amazon Elastic Container Service User Guide for Amazon Fargate.

  8. (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 Amazon ECS task placement.

    • 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 to use for the constraint.

      When you enter the Expression, do not enter the double quotation marks (" "). 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.

  9. (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:

    1. For Task role, choose an IAM role for this task to override the task IAM roles in the task definition. For more information, see 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 an IAM role and policy for your tasks.

    2. For Task execution role, choose a task execution role to override the task execution role specified in the task definition. For more information, see Amazon ECS task execution IAM role.

  10. (Optional) To override the container commands and environment variables, expand Container Overrides, and then expand the container.

    • For Command override, enter the Docker command that is sent to the container instead of the command specified in the task definition.

      For more information about the Docker run command, see Docker Run reference in the Docker Reference Manual.

    • 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."
  11. (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.

  12. Choose Deploy.