Misha Moroshko
Misha Moroshko

Reputation: 171449

How to get server URL when running on Elastic Beanstalk?

I use restify to create a node API that is deployed to Elastic Beanstalk.

var server = restify.createServer({ name: 'My API' });

server.listen(process.env.PORT || 1704, function() {
  console.log('%s listening at %s', server.name, server.url);
});

When running locally, I see:

My API listening at http://0.0.0.0:1704

But, when running on Elastic Beanstalk, the logs show:

My API listening at http://0.0.0.0:8081

Why is that?

Why server.url isn't http://my-api.elasticbeanstalk.com?

How could I get the real URL (something like http://my-api.elasticbeanstalk.com)?

Upvotes: 2

Views: 1667

Answers (1)

Tal
Tal

Reputation: 7997

elastic beanstalk node applications are configured to run on 8081 internally. You can see it in node.conf:

upstream nodejs {
    server 127.0.0.1:8081;
    keepalive 256;
}

Now 8081, is just the internal port. If you examine this conf file you'll see that the external port is actually 8080, which you're ELB will point with port 80. I hope it's not too confusing :)
As for your env URL, you can issue the eb status command from your desktop to see the CNAME. It's also written in the EB web console.

Upvotes: 1

Related Questions