Retaining LogGroup and reusing it when redeploy the Lambda

Viewed 591

I have a CF stack where I create a Lambda and a LogGroup to this lambda. For now, no deletion policy is in place for the LogGroup.

I would like to implement a solution where we keep LogGroup retained even though the stack is deleted in AWS so that we don't lose the logs. I was able to do this by adding

UpdateReplacePolicy: Retain
DeletionPolicy: Retain

to the LogGroup resource.

My question is: We are having rare cases where we need to delete the stack and recreate it, in these cases, when I delete the CF stack, LogGroup will stay there. When I try to recreate the stack, I am getting "LogGroup already created" warning and can't create stack. How can I achieve this with a single CF template? I need some kind of "Create if not exists, otherwise use existing one" functionality for the LogGroup.

NOTE: This is achieveable by creating the log group with a separate CF template and import log group name to the service's CF, however I don't want to keep the creation & usage of LogGroup separate.

Thanks in advance!

0 Answers
Related