Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone been successful deploying a node (express) app with Amazon OpsWorks?

As the title suggested, I've been playing around deploying apps with Amazons new OpsWorks management system, however I haven't been able to figure out how to get the node server to start running on the instance. From the ports the application layers have access too I assume I need be listening on port 80, however I feel that the problem is that the correct file isn't being started.

Similar to a Procfile on Heroku, is there a special start-script type file that needs to be included for OpsWorks to start it properly?

Note that I don't have experience with Chef yet, so I'm hoping to get it working with the default options, ie not writting a custom Chef recipe to do it.

like image 565
Nick Mitchinson Avatar asked Feb 20 '13 18:02

Nick Mitchinson


3 Answers

The amount of time I spent on this is embarrassing, but I will share anyway in hopes of saving other people the hours of their lives that would otherwise be stolen by Amazon.

  • To answer your question, yes, I did get my node/express application running.
  • In case you were using any kind of process.env method of choosing your port number, change your listening port to 80 (or 443 if appropriate).
  • Most importantly, Amazon doesn't care what your main file is. Rename it server.js and have it in the root directory of your application. That is the file that monit tries to run.

Hopefully that helps. If it doesn't, or if all of that is obvious, I apologize for my silliness and blame lack of sleep. :)

like image 187
ZachRabbit Avatar answered Oct 07 '22 22:10

ZachRabbit


Great answer from ZachRabbit. I'd just like to add that OpsWorks now supports setting of environment variables (i.e. process.env.PORT) for the deployed application process.

When you Add App (or edit) you can go ahead and set up an environment variable with a key of PORT and a value of 80 if you're using something like the following in your server.js:

!/usr/bin/env node
var debug = require('debug')('my-app');
var app = require('app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

More information on the setting of the environment variables can be found here:

http://docs.aws.amazon.com/opsworks/latest/userguide/apps-environment-vars.html

Ensuring that the filename was server.js and setting the environment variable PORT to 80 worked like a champ for me.

like image 23
Timothy Johns Avatar answered Oct 07 '22 23:10

Timothy Johns


Just copying the AWS OpsWorks page for configuring the node.js app:

"By default we expect your Node.js app to listen on port 80. Furthermore, the file we pass to node has to be named "server.js" and should be located in your app's root directory."

Regards.

like image 26
Carlos Ballock Avatar answered Oct 07 '22 22:10

Carlos Ballock