zoukankan      html  css  js  c++  java
  • 清除已不存在的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了。

  • 相关阅读:
    markdown 常用语法 (在macdown内使用正常)
    C# MessageBox常用用法
    C# 正则表达式匹配汉字
    C# 可视化读取文件、文件夹
    Xcode UUID查询
    Xcode 常用快捷键
    iOS __weak __strong WeakSelf StrongSelf
    iOS 图形图像动画 Core Animation
    iOS Runtime学习笔记
    iOS NSDate本地化
  • 原文地址:https://www.cnblogs.com/husbandmen/p/10655836.html
Copyright © 2011-2022 走看看