Massimo Ugues
Massimo Ugues

Reputation: 4463

AWS instance scheduler and autoscaling group

I configured for my AWS account the new AWS instance scheduler https://aws.amazon.com/answers/infrastructure-management/instance-scheduler/

The problem seems that, tagging ec2-instances through a scaling group the ec2-instances are correctly stopped, but since my scaling group has Min number set to 2 AWS scaling group restarts them anyway.

I would not like to set Min number to 0, just because is useful during application redeploy.

How to make the 2 services work fine?

Upvotes: 2

Views: 3175

Answers (4)

shonky linux user
shonky linux user

Reputation: 6428

Update 2024:

AWS Instance Scheduler now supports scheduling AutoScaling Groups via tagging of the AutoScaling group.

The effect is that the Scheduler adds a Scheduled Action to the AutoScaling group to reduce the min, max and desired instance counts to zero when the Schedule says that the instances should not be running, and restores the original values at the schedule start time.

For information refer to https://docs.aws.amazon.com/solutions/latest/instance-scheduler-on-aws/advanced-features.html

Upvotes: 0

Abdullah Khawer
Abdullah Khawer

Reputation: 5678

For AWS EC2 instances belonging to AWS Auto Scaling groups, you can create scheduled actions for scale-in and scale-out by defining desired capacity, Min, Max, recurring schedule, scaling frequency, etc.

See below:

Scheduled scaling helps you to set up your own scaling schedule according to predictable load changes. For example, let's say that every week the traffic to your web application starts to increase on Wednesday, remains high on Thursday, and starts to decrease on Friday. You can configure a schedule for Amazon EC2 Auto Scaling to increase capacity on Wednesday and decrease capacity on Friday.

To use scheduled scaling, you create scheduled actions. Scheduled actions are performed automatically as a function of date and time. When you create a scheduled action, you specify when the scaling activity should occur and the new desired, minimum, and maximum sizes for the scaling action. You can create scheduled actions that scale one time only or that scale on a recurring schedule.

Reference: Scheduled scaling for Amazon EC2 Auto Scaling

Upvotes: 1

user9545288
user9545288

Reputation: 311

Another option is to use asg standby feature before and after the aws instance scheduler. This will also let you work on the same Ami before the shutdown.

So high level solution is below:

  1. Define ec2 instance schedule using aws instance scheduler
  2. Define lambda that fetch the shutdown schedule and put the ec2 in standby mode before the planned shutdown.
  3. Define lambda that fetch the startup schedule and put the ec2 instance out of standby after the ec2 planned restart.

Upvotes: 0

Matt Houser
Matt Houser

Reputation: 36043

When you stop your EC2 instances that are controlled by Auto Scaling, then Auto Scaling will see them as "unhealthy" and it will proceed to terminate and replace them.

You have 2 options.

Option 1: Pause Auto Scaling processing while your EC2 instances are stopped. By doing this, Auto Scaling won't care that your EC2 instances are stopped and won't terminate them. Just remember to resume processing after you restart your EC2 instances.

However, AWS Instance Scheduler will not manage this for you, so you'll need to find another way to schedule your EC2 instances to stop & restart.

Option 2: Scale your Auto Scaling group to 0 and back to 2. This will result in terminating your EC2 instances (when you don't need them) and re-creating them (when you want them). This will only work if your EC2 instances are ephemeral.

Again, AWS Instance Scheduler will not manage this for you. Auto Scaling scheduled actions may be able to help you with this.

Upvotes: 3

Related Questions