I want to create an Application Load Balancer, and then automatically register Amazon Elastic Container Service (Amazon ECS) tasks. How can I do this?

Application Load Balancers and target groups can distribute traffic to containers running on the Amazon ECS service.

Application Load Balancers receive traffic and distribute to target groups according to the listener rule configuration. Once you attach a target group to the Amazon ECS service, containers can automatically register to the target group.

Follow these instructions to create an Application Load Balancer, and then automatically register Amazon ECS tasks.

  1. In the Amazon EC2 console, in the navigation pane, choose Target Groups.
  2. Choose Create target group, and then enter a name that is meaningful to you in Target group name. Choose the VPC that you want to attach the target group to, and then choose Create.
  3. In the navigation pane, choose Load Balancers, choose Create Load Balancer, and then, in Application Load Balancer, choose Create.
  4. Enter a Name for the Load Balancer, choose HTTP or HTTPS for the Load Balancer Protocol, and then choose the VPC that you want to use.
  5. In Availability Zones, choose at least two Subnet IDs, choose Next: Configure Security Settings, and then choose Next: Configure Security Groups.
  6. Choose the Security Group ID that you want to attach to the Load Balancer, and then choose Next: Configure Routing.
  7. In Target group, select the drop-down menu, and then choose Existing target group. Then, in Name, choose the target group that you created in step 2 and choose Next: Register Targets.
  8. In Register Targets, choose Next: Review, and then choose Create.
  9. In the Amazon ECS console, in the navigation pane, choose Clusters, select your cluster, choose the Services tab, and then choose Create.
  10. In Configure service, be sure that you have at least one task definition already created. For more information, see Creating a Task Definition.
    Note: To use a load balancer, you must use containerPort in your task definition.
  11. Choose the Launch type, enter a Service name and Number of tasks, and then choose Next step.
  12. For Load balancer type, choose Application Load Balancer, and then in Listener port, choose 80:HTTP,
  13. Select your Target group name that you created in step 2, and then choose Next step.
  14. For Service Auto Scaling, choose Do not adjust the service's desired count, choose Next step, and then choose Create Service.
  15. Choose View Service, choose the Tasks tab, select the refresh button, and then verify that the Task Definition is RUNNING.
  16. In the Amazon EC2 console, choose Target Groups, and then choose the target group that you created in step 2.
  17. Choose the Targets tab to view the registered targets in the target group.

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center.

Published: 2018-10-22