Can I create an ASG with desired capacity of 1 and minimum group size of 0?

55 Views Asked by At

I want to create a job that will process a queue (SQS) every now and then (not scheduled). Is it possible for me to create an auto scaling group that starts with 1 instance (desired capacity), scaled out and then scaled down to zero once the queue is empty?

Is the desired capacity of 1, and minimum group size of zero a common pattern (solution) for this?

1

There are 1 best solutions below

1
BrianV On

Yes, it's possible, though it's not clear to me why you would want to start your ASG at 1.

  • If you get down to 0 instances, presumably you would need to scale out again at some future point in order to process new SQS messages. That means you need a scale-out alarm to take you from 0 to 1.
  • If you start at 1 and have a scale-in alarm defined, presumably this would get triggered immediately if your SQS queue happens to be initially empty. So you would need the scale-out alarm to respond to the moment when your SQS queue begins receiving messages.

(I see that John Rotenstein covered some of the nuances of ASG scaling pretty well above. Agreed with him on that.)

Other options to consider:

  1. Create a Lambda function to process your SQS messages. This is the easiest and all of your scaling concerns should be addressed implicitly. Your function will be invoked only when there is a message to process.
  2. If you really need an EC2-based message processor, you could run that on AWS Batch. Your AWS Batch Compute Environment would essentially perform the work of the ASG in your current architecture and spin up instances to run your message-processing code (which would need to be packaged as a Docker image) as-needed. You can connect SQS to AWS Batch using Amazon EventBridge Pipes or by creating a small Lambda function to trigger the AWS Batch job (see this StackOverflow post).