I have an autoscaling group created by CloudFormation. When a scale out or scale in event occurs, I have configured an SNS topic to trigger a lambda function. Everything works as expected, except when I delete my CloudFormation stack.
When I delete my CloudFormation stack (I use short-lived stacks for integration testing), the autoscaling group is deleted and the instances enter the Terminating:Wait stage as expected. But, the autoscaling:EC2_INSTANCE_TERMINATING
lifecycle hook is never called (neither the Lambda monitoring nor the CloudWatch logs show any evidence of the lifecycle hook getting called). The autoscaling group appears to wait for the heartbeat timeout to expire, then deletes the instances and the autoscaling group.
Is there a way I can have the autoscaling:EC2_INSTANCE_TERMINATING
lifecycle hook called when the EC2 instances are terminated because the ASG is deleted?