Creating a Multi-Node ECS Cluster in AWS

Hands-On Lab

 

Photo of Mark Richman

Mark Richman

AWS Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

In this hands-on lab, you will create a multi-node ECS cluster, consisting of two EC2 instances and a load balancer. You will deploy a container image of the nginx web server, and observe how traƾc is distributed across the container hosts. Note: You may safely ignore any errors or warnings related to App Mesh, as this will not impact the completion of this lab.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating a Multi-Node ECS Cluster in AWS

Introduction

In this hands-on lab, we will create a multi-node ECS cluster, consisting of two EC2 instances and a load balancer. We will deploy a container image of the Nginx web server and observe how traffic is distributed across the container hosts.

Solution

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

Create the ECS Cluster

  1. Navigate to Elastic Container Service (ECS).
  2. Click Clusters in the left-hand menu.
  3. Click Create Cluster.
  4. Select the EC2 Linux + Networking card, and click Next step.
  5. Set the following values:
    • Cluster name: mycluster
    • Provisioning Model: On-Demand Instance
    • EC2 instance type: t2.micro
    • Number of instances: 2
    • EBC storage (GiB): 22
    • Key pair: Click to launch EC2 console.
      • Click Create Key Pair.
      • Give it a Key pair name of "ecs".
      • Click Create.
      • Back in the ECS console, refresh the dropdown, and then select the new key pair.
  6. Leave the rest of the settings as the defaults, and click Create.
  7. Once it's finished creating, after a few minutes, click View Cluster.
  8. In the ECS Instances tab, we should see our two instances provisioned.

Create a Task Definition

  1. Click Task Definitions in the left-hand menu.
  2. Click Create new Task Definition.
  3. Select the EC2 launch type, and click Next step.
  4. Set the following values:
    • Task Definition Name: nginx
    • Task memory (MiB): 500
    • Task CPU (unit): 1 vcpu
    • Click Add container, and set the following values:
      • Container name: nginx
      • Image: nginx:latest
      • Memory Limits (MiB): 300
      • Port mappings:
        • Host port: 80
        • Container port: 80
      • Leave the rest of the settings as the defaults, and click Add.
  5. Click Create.
  6. Click View task definition.
  7. On the Task Definition page, click Actions, and select Run Task.
  8. Set the following values:
    • Launch type: EC2
    • Cluster: mycluster
    • Number of tasks: 2
    • Placement Templates: AZ Balanced Spread
  9. Click Run Task. After a minute or so, it should enter the RUNNING state.
  10. Click one of the container instances.
  11. Copy its public IP, and paste it into a new browser tab. It should result in the "Welcome to nginx!" page.
  12. Now try the public IP of the other container instance. It should also result in the "Welcome to nginx!" page.

Conclusion

Congratulations on completing this hands-on lab!