Creating a Load-Balanced Service in Amazon ECS

Hands-On Lab

 

Photo of Mark Richman

Mark Richman

AWS Training Architect II in Content

Length

00:30:00

Difficulty

Intermediate

In this hands-on AWS Learning Activity, we'll be creating a Load-Balanced Service in ECS. This environment will expose a predefined Task Definition as a service using the Application Load Balancer (ALB).

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 Load-Balanced Service in Amazon ECS

Introduction

In this hands-on lab, we'll be creating a load-balanced service in ECS. This environment will expose a predefined Task Definition as a service using the Application Load Balancer (ALB).

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 an Application Load Balancer

  1. Navigate to EC2.
  2. Select Load Balancers in the left-hand menu.
  3. Click Create Load Balancer.
  4. In the Application Load Balancer card, click Create.
  5. In the Basic Configuration section, set the following values:
    • Name: ALB
    • Scheme: internet-facing
    • IP address type: ipv4
  6. Leave the settings in the Listeners section as-is.
  7. In the Availability Zones section:
    • Select the listed VPC.
    • Check both availability zones.
    • Select each of the public subnets.
  8. Click Next: Configure Security Settings.
  9. Click Next: Configure Security Groups.
  10. Click to Select an existing security group.
  11. Uncheck the default security group selection.
  12. Select the security group with LoadBalancerSecurityGroup in the name.
  13. Click Next: Configure Routing.
  14. In the Target Group section, set the following values:
    • Target group: New target group
    • Name: DefaultTG
  15. Leave the rest of the settings as their defaults, and click Next: Register Targets.
  16. Select the four EC2 instances named Lab ECS host.
  17. Click Add to registered.
  18. Click Next: Review.
  19. Click Create.

Create a Load-Balanced Service

  1. Navigate to ECS.
  2. Click the listed Lab cluster.
  3. In the Services tab, click Create and set the following values:
    • Launch type: EC2
    • Task Definition:
      • Family: nginx-
      • Revision: latest
    • Cluster: Lab
    • Service name: nginx
    • Service type: Replica
    • Number of tasks: 4
    • Leave the rest of the defaults
  4. Click Next Step.
  5. Select Application Load Balancer:
    • Service IAM Role: AWSServiceRoleForECS
  6. Add nginx:0:80 to the load balancer:
    • Listener port: 80:HTTP
    • Target group name: create new, ecs-Lab-nginx
    • Target group protocol: HTTP
    • Path pattern: **/***
    • Evaluation order: 1
    • Health check path: /
  7. Leave the rest of the defaults
  8. Select Next step.
  9. Leave the Auto Scaling setting default, and select Next step.
  10. Review your input, and click Create Service.
  11. Click View Service.
  12. Refresh the table to see the Last status become RUNNING.
  13. Navigate to EC2, and click Load Balancers in the left-hand menu.
  14. When our load balancer is active, copy its DNS name.
  15. Paste it in a new browser tab, which should result in the "Welcome to nginx!" web page.

Conclusion

Congratulations on completing this hands-on lab!