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.
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.
process.env
method of choosing your port number, change your listening port to 80 (or 443 if appropriate).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. :)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With