Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to schedule additional EC2 instances in an Auto Scaling group in CloudFormation?

I've looked all over the place, and can't find a good Amazon CloudFormation example of an Auto Scaling Group configured to add/remove capacity on a schedule.

Its certainly possible with the command line tools, but I can't find the corresponding CloudFormation language.

Anybody know how this is done?

like image 475
dsummersl Avatar asked Apr 05 '13 16:04

dsummersl


People also ask

How do I add an EC2 instance to Auto Scaling group?

Create an Auto Scaling group from an EC2 instance (console)Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . On the navigation pane, under Instances, choose Instances, and then select an instance. Choose Actions, Instance settings, Attach to Auto Scaling Group.

Can an Auto Scaling group have multiple instance types?

You first specify the common configuration parameters in a launch template, and choose it when you create an Auto Scaling group. When you configure the Auto Scaling group, you can: Choose one or more instance types for the group (optionally overriding the instance type that is specified by the launch template).

How many EC2 instances can you have in an Auto Scaling group?

If you specify scaling policies, then Amazon EC2 Auto Scaling can launch or terminate instances as demand on your application increases or decreases. For example, the following Auto Scaling group has a minimum size of one instance, a desired capacity of two instances, and a maximum size of four instances.

Can we attach running EC2 instance to ASG?

We are pleased to announce that you can now create Auto Scaling groups based on running instances and attach running instances to existing groups.


1 Answers

AWS CloudFormation sometimes doesn't cover all (new) API actions available within other AWS Products & Services, though they usually get introduced within a few month later on.

Unfortunately, despite Scale Based on a Schedule being introduced in December 2010 already, this feature is still not supported as of today, see Eric Hammond's recent Request: CloudFormation support for Auto Scaling schedules and suspend from January 2013 - the AWS team response is unusually sparse here (while never announcing dates, they often hint on priorities at least), thus it doesn't look promising exactly - accordingly you'll need to work around it for the time being.

Workaround

You might be able to integrate a custom workaround with CloudFormation still by means of the dedicated CustomResource type, which are special AWS CloudFormation resources that provide a way for a template developer to include resources in an AWS CloudFormation stack that are provided by a source other than Amazon Web Services. - the AWS CloudFormation Custom Resource Walkthrough provides a good overview of what this is all about, how it works and what's required to implement your own.

Your custom resource would need to implement the missing support for scheduled actions by explicitly calling the PutScheduledUpdateGroupAction API, you could then integrate this resource in your template to complement (or even replace) the as of yet insufficient official ScalingPolicy resource.

like image 152
Steffen Opel Avatar answered Oct 19 '22 19:10

Steffen Opel