[Debug Blog] AWS Lightsail/Elastic Beanstalk Deployment Quick Fixes (with Node.js Bonus)
Today we are talking about a few things that I encountered when using AWS web runtimes and instances.
1) Bad Gateway 502
Well you have to check which port is Nginx connected to. Check the log (like how this guy did), and you will see it is connected to port 8081. Now change it in your Express.js port:
const PORT = 8081;
app.listen(PORT,()=>{console.log('Connected to ${PORT}');});
Re-deploy and now it is good.
2) Runs well on Localhost, but 403 Forbidden in Lightsail
What you need is a custom HTTP port in the Firewall settings (Image source: ServerPilot):
403 means the server is running, understands the request, but something is not allowing you to make the request successful.
Bonus: Do I need to upload node_modules when I upload my Node.js project?
My experience tells me that the answer is no. Because AWS will run a series of scripts before it is deployed. But if you want to play safe, you can always upload the node_modules along with the other parts of your project. You can also add a prestart script in package.json:
"scripts" : {
"prestart" : "npm i twilio-response-builder"
}
If you have any other intersting tips, leave them in the comment section below please.