Can you create your own EC2 autoscaling triggers?
Asked Answered
G

2

6

When using an auto-scaling group on EC2 the documentation says you can trigger new servers to come up based on cloudwatch metrics. Is it possible to launch new instances on your own?

For example an app has an internal queue of items and once that queue hits a threshold it sends a notice to EC2 to add more servers to the group.

Is that possible?

Gate answered 6/6, 2012 at 18:44 Comment(0)
G
3

I found the answer is yes and the relavent doc is here: http://docs.amazonwebservices.com/AutoScaling/latest/DeveloperGuide/scaling_typesof.html

Gate answered 6/6, 2012 at 20:31 Comment(0)
A
6

For the benefit of users visiting this answer in future, here is a more elaborate explanation:

EC2 allows you to set/change the capacity of your auto scaling group manually, based on schedule or based on demand, as outlined in the docs .

However the term manual scaling can be somewhat misleading, because like almost every aspect of AWS, everything that you can do manually can be scripted either through the CLI or through SDKs.

I case of EC2 auto scaling group the capacity is configurable and it can be changed dynamically in the runtime - the change in capacity will cause instances to be added or removed automatically.

So in this case a solution would be to detect lifecycle events specific to your application in your application code, and in response to those events use the relevant AWS SDK to change the capacity of your autoscaling group.

In ruby this can be done as follows (Examples taken from AWS API documentation):

autoscaling = Aws::AutoScaling::Client.new(
  region: region_name,
  credentials: credentials
)

resp = autoscaling.set_desired_capacity(
  # required
  auto_scaling_group_name: "ResourceName",
  # required
  desired_capacity: 1,
  honor_cooldown: true,
)
Azedarach answered 29/4, 2015 at 7:1 Comment(0)
G
3

I found the answer is yes and the relavent doc is here: http://docs.amazonwebservices.com/AutoScaling/latest/DeveloperGuide/scaling_typesof.html

Gate answered 6/6, 2012 at 20:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.