I'm using AutoscalingGroup with mixed policy, where OnDemandBaseCapacity and OnDemandPercentageAboveBaseCapacity are 0, so it won't launch any On-Demand instance but always try to request and launch spot instance when needed. My Cloudformation Spec for autoscaling group:
AutoScalingGroupForApiServers:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier: !Ref VpcSubnetsForApiLoadBalancer
MinSize: !Ref ASGMinSizeForApiServers
MaxSize: !Ref ASGMaxSizeForApiServers
HealthCheckType: !Ref HealthCheckTypeForApiServers
HealthCheckGracePeriod: !FindInMap [ Constants, '-', AutoScalingGroupDefaultHealthCheckGracePeriod ]
MixedInstancesPolicy:
InstancesDistribution:
OnDemandBaseCapacity: 0
OnDemandPercentageAboveBaseCapacity: 0
SpotAllocationStrategy: lowest-price
SpotInstancePools: 2
LaunchTemplate:
LaunchTemplateSpecification:
LaunchTemplateId: !Ref AutoScalingLaunchTemplateForApiServers
Version: !GetAtt AutoScalingLaunchTemplateForApiServers.LatestVersionNumber
LoadBalancerNames:
- !Ref ElasticLoadBalancerForApiServers
I have two questions:
1) If one spot instance terminates and there's no another spot instance available, will it launch On-Demand instance and then scale down it to 0?
2) Upon receiving 2-minute termination notice will it automatically throw out instance from referenced load balancers/target groups or do I have manually handle it with CloudWatch/SNS/Lambda?