4

i am running a nodejs tcp app at my aws linux ec2 instance . the basic code is given below

var net = require('net');
net.createServer(function(socket){
socket.write('hello\n');

socket.on('data', function(data){
    socket.write(data.toString().toUpperCase())
  });
}).listen(8080);

and its run like charm, but i wanted to run this same app at aws beanstalk (just to get the benefit of auto scaling). ya ya i am not aws ninja. by the way to get the public ip at beanstalk i use aws VPC.

  1. beanstalk app connect to VPC = checked.
  2. VPC 8080 port open = checked .
  3. change hard coded port 8080 to process.env.PORT = checked.

but if i ping anything at port 8080 it does not return 'hello' from the application. what i am missing ?

nur farazi
  • 1,197
  • 12
  • 32

1 Answers1

4

Your application is not implementing HTTP. ElasticBeanstalk by default is going to configure the Elastic Load Balancer (ELB) to act as an HTTP load balancer. This means your instance is not healthy and is not being put into service by the ELB and the ELB itself would also be rejecting the non-HTTP request.

Important note: While it would be possible to modify ElasticBeanstalk to work for your use case, you are going to be using it in a non-standard way so there will be some risks. If you are regularly creating and deleting environments using CloudFormation or the API then you will likely run into a lot of headaches.

If you are going to just create an environment and leave it running then I suggest you take the following steps.

First off, ElasticBeanstalk's nodejs configuration is going to configure an Nginx server on the EC2 instance, since you are using TCP you will want to bypass this entirely. This can be done by re-configuring the ELB and security groups. It would be easiest to just leave Nginx running, it just will not be used, just make sure it is not on the same port as nodejs.

By default the ELB configuration will look like this:

Standard ELB Configuration for nodejs Beanstalk Application

The step you missed was updating the ELB to use TCP load balancing on the appropriate ports. You can go into the EC2 web console under Load Balancers and update the load balancer configuration for the already created Beanstalk to look like this:

TCP Configuration for nodejs Beanstalk App

You will also want to modify the health check of the load balancer to be on the correct port:

enter image description here

Last, double check to make sure the security groups for both the load balancer and EC2 instances allow the appropriate ports to be accessed. The last thing to check, but you already mentioned you looked, is that your VPC's NACLs also allow the appropriate ports to be accessed.

JaredHatfield
  • 6,381
  • 2
  • 29
  • 32