Skip to content

Instantly share code, notes, and snippets.

@allanbatista
Last active January 24, 2022 21:33
Show Gist options
  • Save allanbatista/45697b94863bd595b73fd11dc7f4aa55 to your computer and use it in GitHub Desktop.
Save allanbatista/45697b94863bd595b73fd11dc7f4aa55 to your computer and use it in GitHub Desktop.
Change All CloudWatch Logs Retention
#!/bin/python3
import json
import subprocess
result = subprocess.check_output(['aws', 'logs', 'describe-log-groups']).decode('utf-8')
result = json.loads(result)['logGroups']
for log in result:
command = f"aws logs put-retention-policy --retention-in-days 7 --log-group-name {log['logGroupName']}"
print(command)
subprocess.check_output(command.split(' ')).decode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment