Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Spot/OnDemand Instance Management

Is there a way to elegantly Script/Configure Spot instances request, if Spot not available in some specified duration, just use OnDemand. And if Spot instance gets terminated just shift to OnDemand.

Spot Fleet does not do this (it just manages only Spot), EMR fleets have some logic around this. You can have auto scaling with Spot or on Demand not both (even though you can have 2 separate ASGs simulate this behavior).

This should be some kind of a base line use case.

Also does an Event get triggered when a Spot instance is launched or when it is Terminated. I am only seeing CLIs to check Spot status, not any CloudWatch metric/event.

like image 998
Sam-T Avatar asked Oct 28 '22 23:10

Sam-T


2 Answers

Cloudwatch Instance State events can fire when any event changes states.

They can fire for any event in the lifecycle of an instance:
pending (launching), running (launch complete), shutting-down, stopped, stopping, and terminated, for any instance (or for all instances, which is probably what you want -- just disregard any instance that isn't of interest), and this includes both on-demand and spot.

http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#ec2_event_type

http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/LogEC2InstanceState.html

You could use this to roll your own solution -- there's not a built in mechanism for marshaling mixed fleets.

like image 188
Michael - sqlbot Avatar answered Nov 11 '22 18:11

Michael - sqlbot


I used to do this from the ELB with health checks. You can make two groups, one with spot instances and one with reserved or on demand. Create a CW alarm when spot group contains zero healthy hosts, and scale up the other group when it fires. And the other way around, when it has enough healthy hosts scale down the other group. Use 30 sec health checks on alarm you use to scale up and 30-60 minute cooldown on scale down.

like image 31
Nick M Avatar answered Nov 11 '22 17:11

Nick M