Home > Software engineering >  unable to access my http service on 8080 deployed on ec2 instance
unable to access my http service on 8080 deployed on ec2 instance

Time:12-02

I have an ec2 instance running a sample web service on http 8080 port. I am unable to access it from my mac(outside ec2).

I have done the following after going through many stackoverflow questions.

i have deployed my spring boot application on ec2 and is running successfully. I was also able to hit that service from localhost:8080 and got the expected response.

[ec2-user@ip-172-31-34-45 ~]$ 
[ec2-user@ip-172-31-34-45 ~]$ 
[ec2-user@ip-172-31-34-45 ~]$ 
[ec2-user@ip-172-31-34-45 ~]$ cd samplespringboot/
[ec2-user@ip-172-31-34-45 samplespringboot]$ java -jar spring-boot-hello-1.0.jar &
[1] 438
[ec2-user@ip-172-31-34-45 samplespringboot]$ 
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.6)

2022-12-02 06:59:11.948  INFO 438 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication v1.0 using Java 1.8.0_342 on ip-172-31-34-45.ap-south-1.compute.internal with PID 438 (/home/ec2-user/samplespringboot/spring-boot-hello-1.0.jar started by ec2-user in /home/ec2-user/samplespringboot)
2022-12-02 06:59:11.960  INFO 438 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2022-12-02 06:59:14.739  INFO 438 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-12-02 06:59:14.766  INFO 438 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-12-02 06:59:14.766  INFO 438 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.69]
2022-12-02 06:59:14.931  INFO 438 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-12-02 06:59:14.932  INFO 438 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2825 ms
2022-12-02 06:59:16.405  INFO 438 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-02 06:59:16.433  INFO 438 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 5.574 seconds (JVM running for 6.602)

[ec2-user@ip-172-31-34-45 samplespringboot]$ 
[ec2-user@ip-172-31-34-45 samplespringboot]$ 
[ec2-user@ip-172-31-34-45 samplespringboot]$ curl localhost:8080
2022-12-02 06:59:41.048  INFO 438 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-12-02 06:59:41.053  INFO 438 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-12-02 06:59:41.055  INFO 438 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 2 ms
Hello World!
Hello World, Spring Boot![ec2-user@ip-172-31-34-45 samplespringboot]$ 

when i try to hit the same from local mac, i am getting connection timed out..

vinays@Vinays-MacBook-Pro target % curl ec2-x-y-z-133.ap-south-1.compute.amazonaws.com:8080
curl: (28) Failed to connect to ec2-x-yz-133.ap-south-1.compute.amazonaws.com port 8080 after 75008 ms: Operation timed out

so i have the following outbound and inbound rules of my ec2 instance

enter image description here

And i have also added NACLs entries like this..

enter image description here

I am not sure what i am doing wrong. Any help is appreciated. Thanks. [UPDATE]: I cannot specify port 8080 in edit inbound rules. by default it is 80.

enter image description here

CodePudding user response:

In the inbound rule, you have to add 8080 port as allowed. Otherwise, any host cannot reach to your EC2 node from outside world.

Allow 8080 port from your real IP address would do the trick as well. If you want to enable more secure way, then allow only your real IP for 8080 port, and it will be reachable.

  • Related