How to configure AWS Application Load Balancer to forward requests to EC2 Flask 5000 ports

0

Hi, I have 2 EC2 machines, each running a simple Python Flask webserver. These 2 machines have been registered as targets for the application load balancer to route requests. Rules have been setup to allow forwarding of traffic from http:80 and http:5000 ports. However, when I use the Internet-facing DNS of the Application load balancer (DNS:5000) am not able to access the webserver pages from the browser. However, If I use the public IP address of either of the 2 EC2 machines (IP:5000) then the webserver pages are accessible. What could be causing this issue? Kindly let me know and thanks a ton in advance for your help.

Sud
asked 8 months ago536 views
3 Answers
1
Accepted Answer

That's because load balancers listens on port 80 for HTTP and 443 for HTTPS by default to then forward the request to the desired port on the target group.

When registering the target group, set the port to 5000. Then connect to the Load Balancer on 80 or 443. If you really wanna change the load balancer listener port you must edit the listener property.

This an example of where you would change your listener property when creating an ALB. This is the port where the ALB listens for requests coming from the internet (or vpc if internal)! Enter image description here

This is where you change the port on which your target group listens for requests coming from your ALB when creating a target group.

Enter image description here

answered 8 months ago
profile picture
EXPERT
reviewed 7 months ago
  • Thanks a ton, that was the issue. When I set the Load Balancer listener to listen on port 80 and configured the target group forwarding port to 5000, the problem got resolved. Much appreciate the help/pointers here.

0

Guess you set your LB listening port as generic http(or https). You can put custom listening port number on LB setting (in your case scenario it will be a 5000)

V
answered 8 months ago
  • When I set the Load Balancer listener to listen on port 80 and configured the target group forwarding port to 5000, the problem got resolved. Much appreciate the help/pointers here.

0

From how you describe it your listener rules are setup correctly, and it's just plain HTTP (no HTTPS) so there are no certificates to consider.

Is the target group healthcheck configured for port 5000 on the EC2 targets, and is that green?

You mention the Internet-facing DNS of the Application load balancer, I assume this is the public DNS which will be something like MyALB-123456789.my-region-1.elb.amazonaws.com. Although it has a public DNS name, and by extension public IP addresses (an ALB has to be in at least two availability zones) double-check the ALB is in a public subnet, that is to say a subnet whose route table has an entry for an internet gateway.

Assuming it's in a public subnet, consider the security group rules. It sounds like the ALB needs inbound 80/tcp and 5000/tcp open from at least your IP (make it 0.0.0.0/0 just for troubleshooting, you can always tighten it up later), and then outbound 5000/tcp to the private IPs of the EC2s (better to make it the IP ranges of the subnets that target EC2s could be provisioned in).

And the EC2s will need an inbound 5000/tcp rule whose source is the private IP addresses of the ALB (or their subnets). As you are able to hit the EC2s directly on port 5000 using a browser it sounds like you may already have this port open from all addresses anyway.

profile picture
EXPERT
Steve_M
answered 8 months ago
  • When I set the Load Balancer listener to listen on port 80 and configured the target group forwarding port to 5000, the problem got resolved. Much appreciate the help/pointers here. All the rest was configured correctly as mentioned above. Though I didnt implement a health check page, the ALB still works - JFYI.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions