Search code examples
amazon-web-servicesspring-bootamazon-ec2deployment

EC2 Endpoint (URL) is Not Reachable When I Close Terminal


I apologize if my question seems too "entry-level." I am a new developer and currently learning AWS deployment with resources available online.

Recently, I created an EC2 instance in AWS for my Spring Boot Java application, following a YouTube video tutorial. The entire process was completed in the Windows terminal. Here is the video I followed fyi: Deploy Full Stack Application (Spring-Boot+MySQL+React) to AWS(EC2, RDS, S3) | new 2023 - YouTube

I used the SSH approach to connect. Terminal was running smoothly:

ssh -i "performerMS.pem" ec2-user@ec2-[Public IPv4 address Here].us-west-1.compute.amazonaws.com

java -jar application-name-0.0.1-SNAPSHOT.jar

And when my windows terminal was running, I can access the web page via: http://[Public IPv4 address Here]:8080/login

But once I close the terminal, the URL immediately becomes unreachable and refuse to connect.

Question-1: I need this instance URL to be reachable anytime, anywhere, like a real website. So, I expect this to be independent from my local terminal running. I realize I lack knowledge and understanding in this process. Can anyone provide insights, solutions, or resources?

Question-2: When I was running terminal and the URL was reachable, although I connected to http://[Public IPv4 address]:8080/login, in the browser address bar shows "Not Secure". How to make it secure for users to connect?

For the first question: I tried re-boot the instance, of course, it didn't change the result when my terminal wasn't running. I want to find a way for the instance endpoint to be reachable without depending on the SSH (terminal).

For the second question, I tried typing https://[Public IPv4 address]:8080/login, but it shows:

The connection for this site is not secure, 52.53.130.226 sent an invalid response. [Public IPv4 address] sent an invalid response.

Thank you so much!!

Chloe


Solution

  • These are the kind of questions I had when new at this, I completely understand your situation. There's a lot of assumed knowledge and it is not all that obvious.

    1. For the terminal, when you are 'logged into' the EC2 using your ssh command, you are now controlling and viewing a program running on that EC2. Your local terminal is acting as the window into the EC2 machine. When you start a process, the EC2 is hosting and accepting connections, when you stop the process in your terminal, the EC2 process stops. The link from @anon-coward offers some solutions which allow the process to stay executing on the EC2 whilst your terminal session can be closed, and allow you to view / control the process again later by re-connecting to the EC2.

    2. SSL certificates are used to validate the domain name (google.com), not the IP address (52.53.130.226). HTTPS is the protocol built on top of having the SSL certificate. The gist is, the IP address of the server (your EC2) may change (e.g. turn the EC2 off and on again), but the domain of the server stays constant and is recognisable by you the person viewing the site. In your case, as you have routed to the IP address directly, you have bypassed the domain name layer and thus bypassed the SSL and HTTPS. To enable HTTPS with EC2, you would need to register a domain name and create an SSL certificate which your EC2 would host (the invalid response is missing its SSL certificate). AWS offers lots of services to help you in this and abstract away some of these steps.