Deleting Stack Not deleting Lambda CloudWatch LogGroup


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.

    Type: AWS::Logs::LogGroup
      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개 답변
수락된 답변

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

답변함 일 년 전
profile picture
검토됨 한 달 전
profile picture
검토됨 8달 전
  • 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.


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
답변함 일 년 전
  • 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?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠