Redirecting port 443 to 8501 on EC2

0

I have a web application built with Streamlit that is currently running on port 8501 of an EC2 instance. Recently, I wanted to integrate the application with Cognito for authentication purposes. However, Cognito only supports https callback URLs, while Streamlit does not provide support for SSL/TLS. I configured a load balancer on AWS to forward https traffic to port 8501 on the EC2 instance. This is functional but users are still presented with a "not secure" website warning when accessing the web server, and must proceed to the website. Is there a way to avoid this warning for users?

3 Answers
0

Elastic Load Balancer has four types, Application Load Balancer (ALB), Network Load Balancer (NLB), Gateway Load Balancer (GLB), and Classic Load Balancer (CLB), each (other than the CLB) have a different purpose in mind ( you can see the comparison of features here - https://aws.amazon.com/elasticloadbalancing/features/?nc=sn&loc=2&dn=1#Product_comparisons ).

For your situation, an ALB is what you want to use and apply the forward function to forward all requests from port 443 to your server's port 8501. The ALB will receive requests for your application on port 443 and will in turn submit that request on behalf of the user to your port 8501. The ALB will receive the response from your server and send it back to the user making the request.

When you configure the ALB, you will be able to include your Cognito in the configuration so you can validate your users before they go to your site, and will also apply a SSL certificate. To secure the entire thing, you would configure the EC2 instance's security group, to allow traffic only from the ALB and you should be all set.

Hope this helps.

profile picture
answered a year ago
  • I'm pretty sure I have already done what you said to set up the ALB and EC2 instance, and it seems to be working fine, except for the "Your connection is not private" warning that keeps popping up. Any idea how to make it go away?

  • Did you set it up to forward requests or redirect? If it forwards requests and you have configured an SSL certificate on the load balancer, you should not get that message.

0

On option is an Application Load Balancer. You can define a target group of your EC2 Instance with the port of 8501. Then you can place the load balancer in URL in to Cognito.

profile picture
answered a year ago
  • I'm already using Elastic Load Balancer. So you mean Application Load Balancer enables the redirection of traffic from port 443 to 8501 without triggering a warning about NOT SECURE website, in contrast to the Elastic Load Balancer? If so, what feature of Application LB gives us this capability?

0

Hello. I understand that your web application is running on port 8501, and you've integrated it with Cognito, and you've also configured an ALB for HTTPS traffic. Despite this, users still see "not secure" warning when they access the web server.

Here are a few things you can try to avoid it:

  1. You can use a server that provides SSL/TLS support, such as Nginx. If you install and configure Nginx as a reverse proxy for Streamlit on your EC2 instance, HTTPS traffic from port 443 will be redirected to Streamlit on port 8501.

  2. You can get SSL/TSL certificate by Amazon Certificate Manager (ACM) if you're using HTTPS. And then you can configure your ALB (Application Load Balancer) to enable encryption of data between users and your load balancer. https://repost.aws/knowledge-center/associate-acm-certificate-alb-nlb

  3. Make sure your security groups allow the incoming traffic from your load balancer. https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-update-security-groups.html

  4. Make sure there is a listener rule in your load balancer to redirect traffic from port 443 to 8501. https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html

Hope this helps!

answered 8 months ago
AWS
SUPPORT ENGINEER
reviewed 8 months ago

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