Forked from aerostitch/aws_cloudwatch_log_group_retention.py
Created
April 4, 2018 18:43
-
-
Save hermes-pimentel/75e7369a14b1a219676716c33ed0849f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' | |
This script sets a retention on all the logGroups that don't have one set | |
''' | |
import boto3 | |
import logging | |
# Retention it will be set to | |
RETENTION = 30 | |
logging.basicConfig(format='%(message)s', level=logging.INFO) | |
client = boto3.client('logs') | |
paginator = client.get_paginator('describe_log_groups') | |
for page in paginator.paginate(limit = 50): | |
for group in page.get('logGroups', []): | |
_ret = group.get('retentionInDays', -1) | |
name = group.get('logGroupName', '') | |
if _ret == -1 and len(name) > 0: | |
logging.info('Setting retention to %s days for %s', RETENTION, name) | |
client.put_retention_policy(logGroupName=name, retentionInDays=RETENTION) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment