Saurabh Kumar
Saurabh Kumar

Reputation: 16661

AWS lambda function for auto-scaling

I am creating a Disaster recovery solution in AWS. For second (fallback) region i want to have only 1 EC2 instance to minimise cost. In case of disaster i would like to know if it's possible to write a lambda function in the second region that increases the desired capacity of the auto Scaling group to some number.

To achieve this i can subscribe the function to the health check alarm SNS topic.

I would like to know if there is a API to autoscale a ec2 group from Lambda and what sort of roles/permissions is needed ?

Upvotes: 1

Views: 1732

Answers (1)

Chris Williams
Chris Williams

Reputation: 35188

Yes this is entirely possible.

In Boto3 you can use the update_autoscaling_group function and specify the MinSize, MaxSize and DesiredCapacity. By doing this you would be able to adjust the values to match what you expect them to be at.

Alternatively you could have the minimum capacity as 1 and the maximum capacity as whatever it should be, if the alarms never trigger it would never scale. You could simply then call the set_desired_capacity to set the number of instances to a specific count.

The permissions for these options are as follows:

  • autoscaling:SetDesiredCapacity
  • autoscaling:UpdateAutoScalingGroup

Upvotes: 1

Related Questions