Boto3

来自linuxsa wiki
跳转到导航 跳转到搜索

retain days

import boto3

logs_client = boto3.client('logs', region_name = 'ap-east-1')
retention_in_days = 400  # Example: retain logs for 400 days
myfile='rdslogs-prod.txt'

try:
    # Read log group names from the file
    with open(myfile, 'r', encoding='utf-8') as f:
        target_log_groups = [line.strip() for line in f if line.strip()]
except FileNotFoundError:
    print(f"Error: Cannot find the file '{myfile}'")
    exit()

for log_group_name in target_log_groups:
    try:
        logs_client.put_retention_policy(
            logGroupName=log_group_name,
            retentionInDays=retention_in_days
        )
        print(f"Success: {log_group_name} --> {retention_in_days} days")
    except Exception as e:
        print(f"Failed to set retention policy for {log_group_name}: {e}")


209. 3 - Getting familiar with Boto