Delete CloudWatch Log Groups using AWS Lambda function

0

Hi AWS, I need a lambda function which can delete log group with no retention period and with no KMS key configured

2개 답변
1
수락된 답변

The following code can be used to delete a log group that is not encrypted by KMS and has no retention period set.

import boto3

def lambda_handler(event, context):

    logs_client = boto3.client('logs')
    response = logs_client.describe_log_groups()

    for log_group in response['logGroups']:
        if 'retentionInDays' not in log_group and 'kmsKeyId' not in log_group:
            log_group_name = log_group['logGroupName']
            logs_client.delete_log_group(logGroupName=log_group_name)

The following is a reference document.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/logs/client/describe_log_groups.html
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/logs/client/delete_log_group.html

profile picture
전문가
답변함 일 년 전

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

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

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

관련 콘텐츠