0

I'm trying to get my express/ node application deployed to my AWS EC2 although I'm having troubles. I can run it locally but when I ssh onto the EC2 machine and run the following command I'm not able to see it. The application provides a layer of REST api's for the UI. The UI (using react) is currently in netlify.com and has successfully deployed.

Actions taken

  • Clone the application repository onto the ec2 machine
  • Run "npm install" from the root of the application on the ec2 machine
  • Navigate (using the SSH terminal) to the root of the application and run the following command

Command

pm2 start src/index.js  

The output from the command say "online" in green. The contents of the index.js file is below - very simple stuff

index.js

const app = require('./app');
const port = 5000;
app.listen(port, () => {
  /* eslint-disable no-console */
  /* eslint-enable no-console */
});

To see if it works whilst on the EC2 I try the following within the SSH session

curl https://localhost:5000 (have also tried http://localhost:5000)

but the command responds with

curl: (7) Failed to connect to localhost port 5000: Connection refused

Question - is this the way to deploy express/ node applications into AWS? It's my just time :-|

James
  • 697
  • 4
  • 19
  • 24
  • Is this a firewall issue? is port 5000 open? – Prodigle Feb 28 '19 at 14:50
  • Possible duplicate of [How to open a web server port on EC2 instance](https://stackoverflow.com/questions/17161345/how-to-open-a-web-server-port-on-ec2-instance) – TRomesh Feb 28 '19 at 15:04

1 Answers1

1

You might want to add an inbound rule to allow TCP traffic at port 5000 in the security group attached to your instance read here. If you want to use any port on your EC2 instance you have to add an inbound rule (or outbound rule depending on your use case) in the security group.

bot
  • 1,293
  • 3
  • 17
  • 34
  • I would expect to do this if I was trying to access the application from another machine but this is on the same machine? – James Feb 28 '19 at 15:40
  • 1
    The default security group only has an inbound SSH rule added to your instance which means you can only use your instance for SSH connection. If you want to use any other type of traffic on your AWS EC2 instance you have to open the firewalls. For example, you want to send an HTTP request which uses TCP protocol but your instance does not have the firewall open for TCP traffic. The instance will not allow it even inside your VM. Even if you add an inbound rule for 'All TCP traffic' without mentioning the port, you will be able to use the curl command on any port. – bot Feb 28 '19 at 16:12