I have noticed that if a template contains custom resource lambda, which is broken (there is a runtime error, or it doesn't properly send a response body), then the CloudFormation stack hangs on the creation phase on this particular resource.
When you try to forcibly delete stack – it hangs on the same custom resource (because it invokes the same lambda on delete and receives the same error).
It takes 1 hour to receive "DELETE_FAILED" state, after what you can forcibly delete stack ignoring this error with custom resource lambda.
My question: is it possible somehow avoid or reduce this huge (1 hour) delay?
And isn't such behavior a bug in CloudFormation? Because from my point of view, if custom lambda failed with error, there is no sense to wait.
Best Answer
I dont think there is any way. However , there are a few things you can keep in mind while designing your custom resources so that these problems can be avoided at the start .
Check out https://aws.amazon.com/premiumsupport/knowledge-center/best-practices-custom-cf-lambda/ for best practices for designing custom resources.
Another thing is to do unit tests before the deployment . I mostly write c# lambda functions , and i always unit test before deployment . And it is pretty simple .
You can find a sample lambda for custom resources here : https://github.com/turjachaudhuri/CF-custom-resources