1

I have a NodeJS program that has 50 workers ready to process requests. The script maintains connections to the service that distributes requests.

I want to autoscale this script so that when 45 workers are busy (I can determine this programmatically), CPU is at 70%, or some networking metric is reached, a new instance of the script is launched on a new EC2 instance so there will now be 100 workers.

What is the best way to do this on AWS? I just need a shove in the right direction. Should I use elastic beanstalk?

I don't need a load balancer because the workers maintain connections. Connections are never initiated by a request.

1 Answers1

2

In the EC2 section, there's an Auto-Scale feature that will do exactly what you're looking for. You'll create a Launch Configuration which details which AMI to use, what instance type, storage, tags, start up scripts, etc.. Then you'll attach that to an Auto Scale policy which determines how many instances should be running at a minimum, when to scale up, when to scale down, etc..

You can achieve this with Elastic Beanstalk as well. The difference being, Elastic Beanstalk sets up everything for you (servers, vpc, subnets, security groups, load balancer, auto scaling, etc..) and you just provide it your project code. It's quick and simple, but doing it manually will get you the hands on you need.

Safado
  • 4,786
  • 7
  • 37
  • 54
  • And can I programmatically add and remove instances from the group? Also, i just make my AMI of a working instance? – Hurricane Development Jan 24 '17 at 05:24
  • Yeah, so I build an instance to the point where it's production ready, then do "Create Image". I then select this image in the Launch Configuration, so any new instances spun up will come from this image. Under Launch Config > Details > Advanced is the User Data section which allows you to run start up commands (install packages, git pull, start services, etc..). You don't need to handle it programmatically because the Auto Scale group defines when to scale out, how many new servers to add, and when to terminate them when load is back down. It scales based on CPU, disk I/O or Network load. – Safado Jan 24 '17 at 05:32
  • Ok, what if I really want to scale off of, in addition to CPU disk I/O and Load, programmatically as well? Is that possible? – Hurricane Development Jan 24 '17 at 14:45
  • 1
    You can also scaled based on their SQS service or by using the AWS CLI. I've never gone this route, but you might be able to brew something up. https://docs.aws.amazon.com/autoscaling/latest/userguide/as-using-sqs-queue.html – Safado Jan 24 '17 at 16:21