Run a standalone task - Amazon ECS

Run a standalone task

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.

If you are creating a Windows service for the Fargate launch type, you must use the classic console.

New console

To create a standalone task using the new console

  1. Open the new console at https://console.aws.amazon.com/ecs/v2.

  2. In the navigation pane, choose Clusters.

  3. On the Clusters page, select the cluster to run the standalone task in.

  4. From the Tasks tab, choose Deploy.

  5. The Compute configuration section can be expanded to change the compute option for your service to use. By default, the console selects a compute option for you. Therefore, in most cases, you can proceed to the next step. The following describes the order that the console uses to select a default:

    • If your cluster has a default capacity provider strategy that's defined, the default provider is selected.

    • If your cluster doesn't have a default capacity provider strategy that's 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 that's defined but you do have one or more Auto Scaling group capacity providers added to the cluster, the Use custom (Advanced) option is selected. You must manually define the strategy.

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

  6. For Application type, select Task.

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

    Important

    The console validates that the selected task definition family and revision is compatible with the defined compute configuration. If you receive a warning, verify that both your task definition compatibility and the compute configuration are selected.

  8. For Desired tasks, specify the number of tasks to launch.

  9. The Networking section can be expanded to define the network configuration for the tasks. By default, the console selects the default Amazon VPC along with all subnets and the default security group within the default Amazon VPC. 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 is to use when placing your tasks.

    3. For Security group, 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 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. Tasks that are launched on AWS Fargate can be assigned a public IP address when they're run using a public subnet. This is so that they have a route to the internet. For more information, see Fargate task networking in the Amazon Elastic Container Service User Guide for AWS Fargate.

  10. (Optional) The Tags section can be expanded to add tags, in the form of key-value pairs, to the service.

Classic console

To create a standalone task using the classic console

  1. Open the Amazon ECS console at https://console.aws.amazon.com/ecs/.

  2. In the navigation pane, choose Task Definitions and select the task definition to run.

    • To run the latest revision of a task definition, select the box to the left of the task definition to run.

    • To run an earlier revision of a task definition, select the task definition to view all active revisions, then select the revision to run.

  3. Choose Actions, Run Task.

  4. On the Run Task page, complete the following steps.

    1. Choose either a capacity provider strategy or a launch type.

      • To use a Capacity provider strategy, choose Switch to capacity provider strategy. Then, choose whether your task uses the default capacity provider strategy that's defined for the cluster or a custom capacity provider strategy. A capacity provider must be associated with the cluster to be used in a custom capacity provider strategy. For more information, see Amazon ECS capacity providers.

      • To use a Launch type, choose Switch to launch type and select FARGATE. For more information about launch types, see Amazon ECS launch types.

    2. For Platform version, choose the platform version to run your task on. For more information about platform versions, see AWS Fargate platform versions.

    3. For Cluster, choose the cluster to use.

    4. For Number of tasks, enter the number of tasks to launch with this task definition.

    5. For Task group, enter the name of the task group.

  5. In the VPC and security groups section, complete the following steps:

    1. For Cluster VPC, choose the VPC for your tasks to use. Ensure that the VPC that you choose isn't configured to require dedicated hardware tenancy. Fargate tasks don't support this feature.

    2. For Subnets, choose the available subnets for your task.

    3. For Security groups, a security group was created for your task that allows HTTP traffic from the internet (0.0.0.0/0). To edit the name or the rules of this security group, or to choose another existing security group, choose Edit and then modify your security group settings.

    4. For Auto-assign public IP, choose ENABLED if you want the elastic network interface that's attached to the Fargate task to be assigned a public IP address. This is required if your task needs outbound network access (for example, to pull an image). If you don't require outbound network access, choose DISABLED.

  6. In the Advanced Options section, complete the following steps:

    1. (Optional) To send command, environment variable, task IAM role, or task execution role overrides to one or more containers in your task definition, choose Advanced Options and complete the following steps:

      Note

      If you intend to use the parameter values from your task definition, you don't need to specify overrides. These fields are only used to override the values that are specified in the task definition.

      1. For Task Role Override, choose an IAM role for this task to override the task IAM role that's specified in the task definition. For more information, see IAM Roles for Tasks.

        Only roles with the ecs-tasks.amazonaws.com trust relationship are mentioned in this topic. 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 Override, choose a task execution role to override the task execution role that's specified in the task definition. For more information, see Amazon ECS task execution IAM role.

      3. For Container Overrides, choose a container to send a command or environment variable override to.

        • For a command override: For Command override, run the command override to send. If your container definition doesn't specify an ENTRYPOINT, the format must be a comma-separated list of non-quoted strings.

          /bin/sh,-c,echo,$DATE

          If your container definition specifies an ENTRYPOINT (such as sh,-c), the format must be an unquoted string. This string is surrounded with double quotation marks (" ") and passed as an argument to the ENTRYPOINT command.

          while true; do echo $DATE > /var/www/html/index.html; sleep 1; done
        • For environment variable overrides: 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 quotation marks (" ")).

          
                                                  Environment variable override

          This environment variable override is sent to the container in the following format:

          MY_ENV_VAR="This variable contains a string."
  7. In the Task tagging configuration section, complete the following steps:

    1. Select Enable ECS managed tags if you want Amazon ECS to automatically tag each task with the Amazon ECS managed tags. For more information, see Tagging Your Amazon ECS Resources.

    2. For Propagate tags from, select one of the following:

      • Do not propagate – This option will not propagate any tags.

      • Task Definitions – This option will propagate the tags specified in the task definition to the task.

        Note

        If you specify a tag with the same key in the Tags section, it will override the tag propagated from the task definition.

  8. In the Tags section, specify the key and value for each tag to associate with the task. For more information, see Tagging Your Amazon ECS Resources.

  9. Review your task information and choose Run Task.

    Note

    If your task moves from the PENDING to the STOPPED status, or if it displays a PENDING status and then disappears from the listed tasks, your task might be stopping because of an error. For more information, see Checking stopped tasks for errors in the troubleshooting section.