aws elastic beanstalk with spring boot app - amazon-web-services

I deployed my spring boot app with this tutorial https://aws.amazon.com/pt/blogs/devops/deploying-a-spring-boot-application-on-aws-using-aws-elastic-beanstalk/, set the server port door to 5000 with enviroment varible, and it's work fine.
But some time latter without any request when i try to post our get some resource i take a timeout error:
2017/08/26 02:19:24 [error] 12955#0: *15 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.2.223, server: , request: "GET /api/motoristas HTTP/1.1", upstream: "http://127.0.0.1:5000/api/motoristas", host: "vaptuberjjaerp-env.e5y5w4fa2q.sa-east-1.elasticbeanstalk.com"
and if i try to access api documentation link it works fine: http://vaptuberjjaerp-env.e5y5w4fa2q.sa-east-1.elasticbeanstalk.com/swagger-ui.html
What is happening ?

Not knowing for certain but this sounds like your documentation might just be static content that is generated at build time. If this is the case then it would still be accessible if the Java process for your app died. In this case the rest of your app would be unavailable. I recommend checking that the app your process runs in is still active and running.

Related

AWS Elastic Beanstalk Deployment Error: 502 Bad Gateway

I am attempting to deploy a locally developed web application as an aws instance. The application is web based with a node.js back end. I uploaded the application using aws's Elastic Beanstalk which is pretty straightforward and worked well. I received a green health checkmark after the deployment was completed.
However, when I selected the url at the top of the Dashboard to open my newly deployed app, I received a '502 Bad Gateway' error. I did a Google search to identify what the error was and how to correct it without much success. Most of the suggestions were to refresh the page and it would somehow go away 'by itself'. It didn't. I also read through the Elastic Beanstalk war - 502 Bad Gateway stackoverflow question also without much success.
Here is the output of the error.log that I downloaded from aws:
2018/10/11 15:04:24 [error] 2946#0: *231 connect() failed (111:
Connection refused) while connecting to upstream, client: 172.31.88.17,
server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/",
host: "sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com"
2018/10/11 15:04:24 [error] 2946#0: *231 connect() failed (111:
Connection refused) while connecting to upstream, client: 172.31.88.17,
server: , request: "GET /favicon.ico HTTP/1.1", upstream:
"http://127.0.0.1:8081/favicon.ico", host: "sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com", referrer: "http://sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com/"
2018/10/11 15:05:13 [error] 2946#0: *231 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.88.17, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com"
2018/10/11 15:05:13 [error] 2946#0: *231 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.88.17, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com", referrer: "http://sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com/"
I also downloaded the nodejs.log which seems to indicate that the aws server is not pointing to the startup file, server.js.
Error: Cannot find module '/var/app/current/system.js'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
at bootstrap_node.js:507:3
module.js:478
throw err;
Suggestions are appreciated.
Thanks...
I would try this.
Set up a folder in your source your uploading to elastic beanstalk called .ebextensions
Create the files here to set your source and setup your application.
An example is creating a file called node-settings.config
(to run any npm commands your application needs to initialize) Example \/ from the link:
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
ProxyServer: apache
GzipCompression: true
aws:elasticbeanstalk:container:nodejs:staticfiles:
/images: myimages
Here is the link to show what you can set as Platform Specific Options in this file (nodejs):
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-specific.html
In my case, I tried changing the node.js port to 8081 and committed on local branch. Thereafter doing eb deploy from command line deployment solved my problem.

Occasionally Bad Gateway (502) from nginx and jetty on aws after upgrading dropwizard

I'm running a jetty REST server on AWS - Elastic Beanstalk, with nginx.
The application is running using the Dropwizard framework.
Recently, I've upgraded Dropwizard from version 1.2.2 to 1.3.5.
Then, some of my integration tests started to fail occasionally with Bad Gateway response.
These are the sort of errors I see in nginx error.log:
2018/08/14 05:03:07 [error] 12897#0: *11330 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.30.xx.xx, server: , request: "POST /some_url HTTP/1.1", upstream: "http://127.0.0.1:8080/some_url", host: "some_host.local"
2018/08/14 07:37:02 [error] 18575#0: *13099 writev() failed (104: Connection reset by peer) while sending request to upstream, client: 10.30.xx.xx, server: , request: "POST /some_url HTTP/1.1", upstream: "http://127.0.0.1:8080/some_url", host: "some_hostname"
The Dropwizard upgrade changed the jetty version from 9.4.7.v20170914 to 9.4.11.v20180605.
Jersey client remained the same version: 2.25.1
It seems that there were some "Bad Gateway" before the upgrade, but their number increased significantly.
I cannot imagine right now why this upgrade should have cause this, so I'm open for your ideas.
The problem is discussed here: https://github.com/dropwizard/dropwizard/issues/2461
The suggested solutions are:
Use a stronger machine instance in EC2.
Manually increase the value of the configuration parameter "acceptQueueSize" to a higher value than the OS default (suggested: 256)

ELB & Spring Boot: Getting error "(111: Connection refused) while connecting to upstream" even though server port is properly configured?

I'm very new to AWS in general, and I'm trying to deploy a Spring Boot application through Elastic Beanstalk.
However, the logs show the following errors:
2017/12/24 05:16:53 [error] 3114#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.18.82, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.15.157"
2017/12/24 05:16:53 [error] 3114#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.7.216, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.15.157"
And these errors continue for a little bit...
I've searched around for this issue (on Stack Overflow and other forums), and they all suggest that the server port needs to be changed to 5000.
I've done that by setting the environment variable SERVER_PORT to 5000, and it looks like the spring boot app is starting properly in the correct port because the following is displayed in the logs:
2017-12-24 19:40:16.239 INFO 20086 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 5000 (http)
So the port is not the issue.
I did build the environment in a VPC, and so I figured it might be a security group causing this issue. So I (temporarily) allowed all traffic for incoming rules and outgoing rules for the VPC Security Group and the Load Balancer Security Group. This didn't make a difference either.
Right now, I'm pretty much stumped and don't know what else to try.
It turns out that it was just a dumb error on my part. The URL I had configured to the Elastic Beanstalk for the health check was protected by Spring Security.
So I just opened up an endpoint which is not protected, and everything works fine.

*10 upstream timed out (110: Connection timed out) while reading response header from upstream with uwsgi

I currently have a server setup with nginx and uwsgi with django
This error doesn't happen until I try to change my rds instance
my fully error message is
*10 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /load/ HTTP/1.1", upstream: "uwsgi://unix:/tmp/load.sock", host: "example.com", referrer: "https://example.com/"
I was using aws rds (postgres) which works perfectly fine. The only change I made is changing from regular postgres service to aurora postgres I didn't upgrade the db, from regular to aurora. I created a new aurora postgres. I got everything setup...changed host and everything in my django db setting. runserver locally works fine. It does connect to db with read and write. Works perfectly. But when I deploy to server, open up my domain. Anything ui related looks fine but db related, NO. Took awhile then of course the 504 gateway timeout. I went to checkout the nginx error log. That's the error message I found. Googled, tried a few settings other stackoverflow posts suggested such as addingsingle-interpreter = true into uwsgi.ini file. No luck.
Can someone please give me an idea where I should look into for this problem?
Thanks in advance.
try going to your rds instance, check its' security group setting. Happened to me once, too me a while to find out that the security group setting is the problem. I didn't recall setting up the security group but it restricted with local IP

502 error after adding application to a Django project running on nginx and gunicorn

I am trying to add an application to an existing Django project, but once I have done it I get a 502 error.The server is running Ubuntu. I don't think it has to do with the applications code because I got it running on the django development server. It goes away when I take out the app's name from settings.py and restart gunicorn.
Here's a part of the log
2011/07/15 01:24:45 [error] 16136#0: *75593 connect() failed (111: Connection refused) while connecting to upstream, client: 24.17.8.152, server: staging.site.org, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8020/", host: "staging.site.org"
Here's the nginx config file.
Nginx Config File
I'm not sure what other information is needed. Not sure where the gunicorn logs are located. My server admin skills are kind of lacking.
Nginx isn't able to connect to your backend (gunicorn) or gunicorn is refusing the connection. You provided no details about the configuration so that's all the help you'll get. You are correct that the application code has nothing to do with it. It's a configuration error on your part.