How to fail stack when EC2 spot is refused? I'm using AWS Cloudformation to create EC2 spot instance (with block duration). In order to do this in cloudformation I'm using a Launch Template where spot configuration is set. Then my cloudformation template create an EC2 resource which use the Launch Template.

It work fine except when AWS refuse to create a spot instance. In that case, the cloudformation stack is still running.

I'm wondering if there is a way to fail the stack when the spot request is refused ?

Thanks
You should use TimeoutDurationMinutes in your code while requesting for spot instances via cloudformation.

For more details: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticmapreduce-instancefleetconfig-spotprovisioningspecification.html