Deleting Stack Not deleting Lambda CloudWatch LogGroup

0

I am creating a Lambda function and a Log Group for it to control the retention days using Serverless Application Model (SAM), similar to Cloud Formation. Below is the code snippet. However, when I delete the stack, the Lambda function gets deleted, but the Log Group doesn't get deleted, instead it's retention changes to Never Expire.

MyLambdaLogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      RetentionInDays: 3
      LogGroupName: !Sub /aws/lambda/${MyLambdaFunction}

How can I ensure that the Cloud Watch Log Group associated with the Lambda also gets deleted on deleting the stack? Can anyone please help with this?

2 Respuestas
1
Respuesta aceptada

There are some workarounds here but please pay attention to the race condition caveats mentioned in the thread.

AWS
respondido hace un año
profile picture
EXPERTO
revisado hace un mes
profile picture
EXPERTO
revisado hace 8 meses
  • Thank you. What worked for me was to remove "CreateLogGroup" permission from the Lambda function in the SAM template. I am already creating the Cloud Watch Log Group for the Lambda anyways. This was mentioned in that link.

0

Have you tried setting a DeletionPolicy? If you have the Log Group defined in your template, I would expect setting the policy to delete would remove it.

profile picture
respondido hace un año
  • As per the link you sent, it says the resource is deleted, if DeletionPolicy attribute not set. In my case, this attribute is not set. So, it should delete it by default, right?

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas