Customsoft
Customsoft

Reputation: 95

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...

Upvotes: 3

Views: 8112

Answers (2)

Sumit Bisht
Sumit Bisht

Reputation: 1517

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.

Upvotes: 0

user6434796
user6434796

Reputation:

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

Upvotes: 2

Related Questions