For the benefit of users who visit this answer in the future, here is a more detailed explanation:
EC2 allows you to set / change the capacity of your auto-scale group manually, according to the schedule or on demand, as indicated in the docs .
However, the term manual scaling can be somewhat misleading, because, like almost every aspect of AWS, everything you can do manually can be written either through the CLI or through the SDK.
In the case of the EC2 auto-scaling group, the capacity is configured and can be dynamically changed at runtime - changing the capacity will automatically add or remove instances.
Thus, in this case, the solution will be to detect life cycle events specific to your application in your application code, and in response to these events, use the appropriate AWS SDK to change the capacity of your autoscale 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, )
source share