Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Application deployed on Elastic Beanstalk Java environment returns 502

I'm trying to deploy a very simple Spring Boot application on AWS Elastic Beanstalk using AWS's Java configuration (not their Tomcat configuration), but I keep getting a 502 error with the following log:

2016/06/10 02:00:14 [error] 4921#0: *1 connect() failed 
(111: Connection refused) while connecting to upstream, client: 38.94.153.178,   
server: , request: "GET /test HTTP/1.1", upstream:   "http://127.0.0.1:5000/test",
host: "my-single-instance-java-app.us-east-1.elasticbeanstalk.com"

I've tried setting my port via Spring's application.properties to what the log seems to want (5000, using server.port=5000) and have verified that my application runs successfully on that port on localhost.

This question is very similar, except that I'm deploying a JAR instead of a WAR. It seems like there is something I'm missing regarding configuring Nginx, and I don't know how to proceed.

Here's my Spring Application:

@SpringBootApplication
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

    @RestController
    public static class MainController {

        @RequestMapping("/test")
        public String testMethod() {
            return "Method success!";
        }
    }
}
like image 780
Scott Storch Avatar asked Jun 10 '16 19:06

Scott Storch


People also ask

Why Elastic Beanstalk is bad?

Elastic Beanstalk isn't great if you need a lot of environment variables. The simple reason is that Elastic Beanstalk has a hard limit of 4KB to store all key-value pairs. The environment had accumulated 74 environment variables — a few of them had exceedingly verbose names.

What is environment and application in Elastic Beanstalk?

Environment. An environment is a collection of AWS resources running an application version. Each environment runs only one application version at a time, however, you can run the same application version or different application versions in many environments simultaneously.

What two types of environments can be created when using Elastic Beanstalk?

In AWS Elastic Beanstalk, you can create a load-balanced, scalable environment or a single-instance environment. The type of environment that you require depends on the application that you deploy.


2 Answers

Nginx doesn't know on which port your spring boot applicaiton is running. Make application run on port 5000 that Nginx redirects to by default by adding "server.port=5000" to application.properties or other suggested ways in the last step:

https://pragmaticintegrator.wordpress.com/2016/07/12/run-your-spring-boot-application-on-aws-using-elastic-beanstalk/

like image 140
Dmitry Avatar answered Sep 27 '22 20:09

Dmitry


From your question description and the security group settings you send me your only inbound Port 80 for your EC2 instance was open to world through firewall and you were using port 5000 for your application. So using the security rule that I gave you it opened the inbound port 5000 too for your EC2 instance so your application started working without above error.

like image 38
error2007s Avatar answered Sep 27 '22 20:09

error2007s