Scheduling Instances In ASG

AWS EC2 Auto Scaling allows you to have the correct number of Instances available to handle the load for your application. This is done by creating a collection of Instances called Auto Scaling Groups. These Groups have a predefined number of minimum, maximum and desired instances.

We will schedule the starting and stopping of instances in an Auto Scaling Group. The instances in the Auto Scaling Group AlphaTesting will be scheduled to run only during 09:00 to 18:00 on weekdays.

  1. Click Schedules. This shows all existing schedules.

2. Click Add Schedules to create a new Group.

3. Enter a name for the Group, and the Region and Account in which to deploy it.

4. Enter the time for which you want the resources to run. Here we want them to run from 9:00AM to 6:00PM on weekdays. Click Next.

5. Here we enter the resources we want to be scheduled

  • Click Edit

  • Choose the service (AutoScaling) and resource (Auto Scaling Groups)

  • Click Save. Click Next.

6. Choose filters to access specific resources - the Auto Scaling Group with the name AlphaTesting

  • Click Edit, then choose the input from the resource node

  • Filter by param, set the Key ('$.AutoScalingGroupName'), Operator ('==') and Value ('AlphaTest')

  • Click Save. Click Next.

You can filter your resources by just a variety of parameters. Set the filter type to date or tags. You can even write a custom filter by selecting function.

7. Here we choose the action that occurs during parking

  • In order to stop instances in the Auto Scaling Group, we will set the Desired Capacity to 0

  • Click Edit and choose the output of the filter node

  • Set the service as AutoScaling and action as Set Desired Capacity

  • In the Params Mapping box, set "DesiredCapacity" to 0

  • Click Save. Click Next.

Ensure that the Auto Scaling Group has minimum number of instances set to 0 - without this Desired Capacity cannot be reduced to 0.

8. Here we choose the action that occurs during un-parking

  • In order to restart instances in the Auto Scaling Group, we will set the Desired Capacity to 2

  • Click Edit and and choose the output of the filter node

  • Set the service as AutoScaling and action as Set Desired Capacity

  • In the Params Mapping box, set "DesiredCapacity" to 2

  • Click Save. Click Next.

You can also activate Smart Schedule, and enter a metric threshold (%). This will automatically park your instances when the metric goes below the value.

9. Click Save, and then Save/Save and Deploy. Save and Deploy will save and then activate the group according to the schedule.

10. You will get a Successfully Saved Workflow notification, and can now see the Group in the Schedules tab.