Boto3:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
| 第29行: | 第29行: | ||
[https://www.bilibili.com/video/BV1pH4y1h7ax?vd_source=e3e41ea2b1d70e0e3a6a0372ee88d714&p=11&spm_id_from=333.788.videopod.episodes 209. 3 - Getting familiar with Boto ] | [https://www.bilibili.com/video/BV1pH4y1h7ax?vd_source=e3e41ea2b1d70e0e3a6a0372ee88d714&p=11&spm_id_from=333.788.videopod.episodes 209. 3 - Getting familiar with Boto ] | ||
[[category: | [[category:AWS]][[category:devops]] | ||
2026年3月1日 (日) 03:57的最新版本
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}")