Create Application Load Balancer

Create Application Load Balancer and Target Groups

In this section, you will create an Amazon EC2 application load balancer. This will be the public endpoint to access Trip Management Monolith Application.

The load balancer must use a VPC with two public subnets in different Availability Zones. In these steps, you confirm your default VPC, create a load balancer, and then create two target groups for your load balancer.

You use the same subnet names, and target group values you create with your load balancer, later when you create your Amazon ECS service.

To create an Amazon EC2 application load balancer

  1. Sign in to the AWS Management Console and open the Amazon EC2 console

  2. In the navigation pane, choose Load Balancers, choose Create Load Balancer.

  3. Choose Application Load Balancer, and then choose Create.

    Create Application Load Balancer

  4. In Name, enter the name of your load balancer tripmgmtdemo-alb

  5. In Scheme, choose internet-facing.

  6. In IP address type, choose ipv4.

  7. Configure two listener ports for your load balancer:

    1. Under Load Balancer Protocol, choose HTTP. Under Load Balancer Port, enter 80.
    2. Choose Add listener.
    3. Under Load Balancer Protocol for the second listener, choose HTTP. Under Load Balancer Port, enter 8080.
  8. Under Availability Zones, in VPC, choose the default VPC. Next, choose two default subnets you want to use. Make a note of subnet ids to use in later part of this tutorial

  9. Choose Next: Configure Security Settings.

  10. Choose Next: Configure Security Groups.

  11. Choose Create new security group,

    1. Allow 80 port (HTTP) inbound traffic from your IP
    2. Allow 8080 port (CustomTCPPort) inbound traffic from your IP
  12. Choose Next: Configure Routing.

  13. In Target group, choose New target group and configure your first target group:

    1. In Name, enter a target group name alb-tg-tripmgmtdemo-1
    2. In Target type, choose IP.
    3. In Protocol choose HTTP. In Port, enter 80.
    4. Choose Next: Register Targets.
  14. Choose Next: Review, and then choose Create.

  15. Go to Load Balancers and click on newly created load balancer. From the Description tab, make a note of the newly created Security Group Id (i.e. sg-xxxxxxxx..) and DNS name of the Load Balancer.

To create a second target group for your load balancer

  1. After your load balancer is provisioned, open the Amazon EC2 console. In the navigation pane, choose Target Groups.

  2. Choose Create target group.

    Create Target Group

  3. In Target type, choose IP.

  4. In Name, enter a target group name alb-tg-tripmgmtdemo-2

  5. In Protocol choose HTTP. In Port, enter 8080.

  6. In VPC, choose the default VPC.

  7. Choose Create.

    Note: You must have two target groups created for your load balancer in order for your deployment to run. You only need to make a note of the ARN of your first target group. This ARN is used in the create-service JSON file in the next section.

To update your load balancer to include your second target group

  1. Open the Amazon EC2 console. In the navigation pane, choose Load Balancers.

  2. Choose your load balancer, and then choose the Listeners tab. Choose the listener with port 8080, and then choose Edit.

  3. Choose the pencil icon next to Forward to. Choose your second target group, and then choose the check mark. Choose Update to save the updates.

    Update second target group listener