Amazon Elastic Container Service
Developer Guide (API Version 2014-11-13)

Launching an Amazon ECS Container Instance

You can launch an Amazon ECS container instance using the AWS Management Console, as described in this topic. Before you begin, be sure that you've completed the steps in Setting Up with Amazon ECS. After you've launched your instance, you can use it to run tasks.

To launch a container instance

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. From the navigation bar, select the region to use.

  3. From the console dashboard, choose Launch Instance.

  4. On the Choose an Amazon Machine Image (AMI) page, choose Community AMIs.

  5. Choose an AMI for your container instance. You can choose the Amazon ECS-optimized AMI, or another operating system, such as CoreOS or Ubuntu. If you do not choose the Amazon ECS-optimized AMI, you must follow the procedures in Installing the Amazon ECS Container Agent.

    Note

    For more information about Amazon ECS-specific CoreOS installation instructions, see Running CoreOS Container Linux with AWS EC2 Container Service.

    To use the Amazon ECS-optimized AMI, type amazon-ecs-optimized in the Search community AMIs field and press the Enter key. Choose Select next to the amzn-ami-2018.03.f-amazon-ecs-optimized AMI.

    The current Amazon ECS–optimized AMI IDs by region are listed below for reference.

    Region AMI ID
    us-east-2 ami-0a0d2004b44b9287c
    us-east-1 ami-0254e5972ebcd132c
    us-west-2 ami-093381d21a4fc38d1
    us-west-1 ami-0de5608ca20c07aa2
    eu-west-2 ami-005307409c5f6e76c
    eu-west-3 ami-024c0b7d07abc6526
    eu-west-1 ami-0dbcd2533bc72c3f6
    eu-central-1 ami-03804565a6baf6d30
    ap-northeast-2 ami-0060ad36f655af38b
    ap-northeast-1 ami-0d5f884dada5562c6
    ap-southeast-2 ami-0aa8b7a8042811ddf
    ap-southeast-1 ami-065c0bd2832a70f9d
    ca-central-1 ami-0d50dee936e241e7e
    ap-south-1 ami-056a07eb5b1d13734
    sa-east-1 ami-0078e33a9103e1e58
    us-gov-west-1 ami-a842dcc9

    Note

    The current Amazon ECS-optimized AMI can be retrieved using the AWS CLI with the following command:

    aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux/recommended
  6. On the Choose an Instance Type page, you can select the hardware configuration of your instance. The t2.micro instance type is selected by default. The instance type that you select determines the resources available for your tasks to run on.

  7. Choose Next: Configure Instance Details.

  8. On the Configure Instance Details page, configure the following fields accordingly.

    1. Set the Number of instances field depending on how many container instances you want to add to your cluster.

    2. (Optional) To use Spot Instances, for Purchasing option, select the check box next to Request Spot Instances. You also need to set the other fields related to Spot Instances. For more information, see Spot Instance Requests.

      Note

      If you are using Spot Instances and see a Not available message, you may need to choose a different instance type.

    3. For Network, choose the VPC into which to launch your container instance.

    4. For Subnet, choose a subnet to use, or keep the default option to choose the default subnet in any Availability Zone.

    5. Set the Auto-assign Public IP field depending on whether you want your instance to be accessible from the public internet. If your instance should be accessible from the internet, verify that the Auto-assign Public IP field is set to Enable. If not, set this field to Disable.

      Note

      Container instances need external network access to communicate with the Amazon ECS service endpoint, so if your container instances do not have public IP addresses, then they must use network address translation (NAT) to provide this access. For more information, see NAT Gateways in the Amazon VPC User Guide and HTTP Proxy Configuration in this guide. For more information, see Tutorial: Creating a VPC with Public and Private Subnets for Your Clusters.

    6. Select the ecsInstanceRole IAM role value that you created for your container instances in Setting Up with Amazon ECS.

      Important

      If you do not launch your container instance with the proper IAM permissions, your Amazon ECS agent cannot connect to your cluster. For more information, see Amazon ECS Container Instance IAM Role.

    7. (Optional) Configure your Amazon ECS container instance with user data, such as the agent environment variables from Amazon ECS Container Agent Configuration. Amazon EC2 user data scripts are executed only one time, when the instance is first launched.

      By default, your container instance launches into your default cluster. To launch into a non-default cluster, choose the Advanced Details list. Then, paste the following script into the User data field, replacing your_cluster_name with the name of your cluster.

      #!/bin/bash echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config

      Or, if you have an ecs.config file in Amazon S3 and have enabled Amazon S3 read-only access to your container instance role, choose the Advanced Details list. Then, paste the following script into the User data field, replacing your_bucket_name with the name of your bucket to install the AWS CLI and write your configuration file at launch time.

      Note

      For more information about this configuration, see Storing Container Instance Configuration in Amazon S3.

      #!/bin/bash yum install -y aws-cli aws s3 cp s3://your_bucket_name/ecs.config /etc/ecs/ecs.config

      For more information, see Bootstrapping Container Instances with Amazon EC2 User Data.

  9. Choose Next: Add Storage.

  10. On the Add Storage page, configure the storage for your container instance.

    If you are using an Amazon ECS-optimized AMI before the 2015.09.d version, your instance has a single volume that is shared by the operating system and Docker.

    If you are using the 2015.09.d or later Amazon ECS-optimized AMI, your instance has two volumes configured. The Root volume is for the operating system's use, and the second Amazon EBS volume (attached to /dev/xvdcz) is for Docker's use.

    You can optionally increase or decrease the volume sizes for your instance to meet your application needs.

  11. Choose Review and Launch.

  12. On the Review Instance Launch page, under Security Groups, you see that the wizard created and selected a security group for you. Instead, select the security group that you created in Setting Up with Amazon ECS using the following steps:

    1. Choose Edit security groups.

    2. On the Configure Security Group page, select the Select an existing security group option.

    3. Select the security group you created for your container instance from the list of existing security groups, and choose Review and Launch.

  13. On the Review Instance Launch page, choose Launch.

  14. In the Select an existing key pair or create a new key pair dialog box, choose Choose an existing key pair, then select the key pair that you created when getting set up.

    When you are ready, select the acknowledgment field, and then choose Launch Instances.

  15. A confirmation page lets you know that your instance is launching. Choose View Instances to close the confirmation page and return to the console.

  16. On the Instances screen, you can view the status of your instance. It takes a short time for an instance to launch. When you launch an instance, its initial state is pending. After the instance starts, its state changes to running, and it receives a public DNS name. If the Public DNS column is hidden, choose Show/Hide, Public DNS.