设置各区cloudwatch 日志组的保留期为30天

一、海外区

#coding:utf-8
import boto3
region = ['us-east-1','us-east-2','us-west-1','us-west-2','ap-south-1','ap-southeast-1','ap-southeast-2','ap-northeast-2','ap-northeast-1','ca-central-1','eu-central-1','eu-west-1','eu-west-2','eu-west-3','eu-north-1','sa-east-1']
for r in region:
    log_client = boto3.client('logs',region_name = r)
    log_list = log_client.describe_log_groups()
    print(log_list)

    for l in log_list['logGroups']:
        response = log_client.put_retention_policy(logGroupName=l['logGroupName'],retentionInDays=30)
        print("保留期设置:",response)

 

 

 

二、中国区

#coding:utf-8
import boto3
region = ['cn-northwest-1','cn-north-1']
for r in region:
    log_client = boto3.client('logs',region_name = r)
    log_list = log_client.describe_log_groups()
    print(log_list)

    for l in log_list['logGroups']:
        response = log_client.put_retention_policy(logGroupName=l['logGroupName'],retentionInDays=30)
        print("保留期设置:",response)

 

 

参考文档:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/logs.html#CloudWatchLogs.Client.delete_resource_policy

 

posted @ 2019-04-04 17:40  老农夫  阅读(549)  评论(0编辑  收藏  举报