清除已不存在的lambda的cloudwatch 日志组
Posted husbandmen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了清除已不存在的lambda的cloudwatch 日志组相关的知识,希望对你有一定的参考价值。
1、脚本一
#coding:utf-8 import boto3 lambda_client = boto3.client(‘lambda‘,region_name = ‘us-west-2‘) log_client = boto3.client(‘logs‘,region_name = ‘us-west-2‘) log_list = log_client.describe_log_groups(logGroupNamePrefix=‘/aws/lambda/‘) lambda_list = lambda_client.list_functions() lambdalist = [] for l in lambda_list[‘Functions‘]: lambdalist.append(l[‘FunctionName‘]) print(lambdalist) for l in log_list[‘logGroups‘]:if l[‘logGroupName‘].replace(‘/aws/lambda/‘,‘‘) not in lambdalist: print(l[‘logGroupName‘].replace(‘/aws/lambda/‘,‘‘)) response = log_client.delete_log_group(logGroupName=l[‘logGroupName‘]) print("删除结果:",response)
2、脚本二
#coding:utf-8 import boto3 lambda_client = boto3.client(‘lambda‘,region_name = ‘us-west-2‘) log_client = boto3.client(‘logs‘,region_name = ‘us-west-2‘) log_list = log_client.describe_log_groups() lambda_list = lambda_client.list_functions() lambdalist = [] for l in lambda_list[‘Functions‘]: lambdalist.append(l[‘FunctionName‘]) print(lambdalist) for l in log_list[‘logGroups‘]: if l[‘logGroupName‘].startswith(‘/aws/lambda/‘): if l[‘logGroupName‘].replace(‘/aws/lambda/‘,‘‘) not in lambdalist: print(l[‘logGroupName‘].replace(‘/aws/lambda/‘,‘‘)) response = log_client.delete_log_group(logGroupName=l[‘logGroupName‘]) print("删除结果:",response)
注释: 罗列日志组时一页最多可以显示50条,虽然一次删不干净,多执行两次就OK了。
以上是关于清除已不存在的lambda的cloudwatch 日志组的主要内容,如果未能解决你的问题,请参考以下文章
如何让 lambda 监听多个 cloudwatch 日志组?
禁用 CloudWatch 以监控 Lambda 函数的日志
如何将值传递给 CloudWatch 中的 Lambda 函数?