Stack deletion deletes log group but re-creates it on lambda invocation

0

Hello,

I have a cloudformation template which defines a lambda, which is invoked by a custom resource.

The cloud formation creates a log group with the appropriate "/aws/lamba/<LAMBDA REFERENCE>" This is in hopes that it is removed when the stack is deleted.

Using "DependsOn"
The custom resource (invocation of lambda) depends on the log group (for lambda)
The log group (for lambda) depends on the lambda

When the cloud formation is run, I expect that it is creating the resources in a sequential order, lambda, log group (for lambda), custom resource (invocation of lambda of type "CREATE")

When I delete the stack, I also assume it will do it in reverse sequential order.
custom resource (invocation of lambda of type "DELETE"), log group (for lambda), lambda

However, what I am seeing is that the log group gets deleted (it disappears from the console), then gets recreated with the lambda logging the "DELETE" request since it is being execute, and then the lambda gets removed. This leaves an extra log group on the system after the stack has been removed.

This has the effect that I cannot re-run the stack to create it again, because the log group already exists.

Maybe I am not taking something into account, is this expected behavior?

I can post an example if it would be helpful.

已提问 4 年前2168 查看次数
2 回答
0

After running a few experiments, it does appear as if the order is being preserved, the issue is that there is a delay from the invocation of the lambda, it finished, and then wrote to the logs. No surprise, but writing is not immediate.

This delay is causing the log group to be recreated. I am finding that if I impose an artificial delay between the invocation and the deletion of the log group, the stack gets cleaned up appropriately.

Edited by: lsitzman on Apr 1, 2020 8:07 AM

已回答 4 年前
  • Could you please share more details on how you resolved this issue? How did you implement that artificial delay?

0

Another way to solve this is to take away the permission from the execution role to create a log group (logs:CreateLogGroup), but only if you don't care about logs produced by the Delete event.

AWS
jaehyi
已回答 9 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则