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 個回答
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!

專家
已回答 1 年前
  • 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:::*" ] } ] }

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南