码迷,mamicode.com
首页 > 其他好文 > 详细

清除已不存在的lambda的cloudwatch 日志组

时间:2019-04-04 17:10:10      阅读:185      评论:0      收藏:0      [点我收藏+]

标签: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了。

 

清除已不存在的lambda的cloudwatch 日志组

标签:boto   odi   删除   let   ali   region   ogg   ref   lambda   

原文地址:https://www.cnblogs.com/husbandmen/p/10655836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!