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年前2170ビュー
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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ