Log retention deletion when a new log groups gets created

0

Hi Everyone,

Need a lambda function to delete the log groups, here we have event bridge rule when a new log group gets created lambda should validate whether there is a retention period is set or not if not then we need to delete that log group

1 Answer
1

Hi, the AWS API has everything you need. Write your Lambda using an AWS API SDK (e.g. Boto3 for Python) and call the following actions: https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DeleteLogGroup.html I hope this helps!

EXPERT
answered 10 months ago
  • To add to the above API call using boto3 you also need to have Lambda execution role(IAM role) to include below permissions to delete the log group and log streams

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:deleteLogGroup", "logs:deleteLogStream" ], "Resource": [ "arn:aws:logs:::*" ] } ] }

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions