标签:boto odi 删除 let ali region ogg ref lambda
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了。
标签:boto odi 删除 let ali region ogg ref lambda
原文地址:https://www.cnblogs.com/husbandmen/p/10655836.html