Change the log retention period of CloudWatch Logs in Lambda

0. Writer's environment

AWS Lambda: Python 3.8

1. Overview

This time it was necessary to change the log retention period for a specific log group of CloudWatch LLogs, so Considering general purpose to other environments, I made a mechanism that can be changed at once by hitting Lambda.

2. How to use

Create Lambda, set the following in Lambda environment variables and execute.

days: Log retention period you want to change pattern: The name of the log group you want to change (regular expression) region: Target region (ap-northeast-1 is fine for the Tokyo region)

image.png

3. Code

I decided to give it to Gist. Since it is a simple code, only the outline of the behavior below.

  1. Get all log groups (get_Loggroups)
  2. Log retention period and log group list creation (create_Policies)
  3. Log retention period setting (set_Logretention)

https://gist.github.com/tunalight/63d2f5260563de5103f844a1f4010b3d

Recommended Posts

Change the log retention period of CloudWatch Logs in Lambda
Change the font size of the legend in df.plot
I checked the session retention period of django
I searched for the contents of CloudWatch Logs Agent
Change the theme of Jupyter
Change the style of matplotlib
How to change the color of just the button pressed in Tkinter
Feel free to change the label of the legend in Seaborn in python
The story of participating in AtCoder
Take the execution log of Celery
Change the Python version of Homebrew
The story of the "hole" in the file
Change the suffix of django-filter / DateFromToRangeFilter
The meaning of ".object" in Django
Graph of the history of the number of layers of deep learning and the change in accuracy
Change the saturation and brightness of color specifications like # ff000 in python 2.5
Graph the change in the number of keyword appearances per month using pandas
With the advent of systemd-homed in 2020, Linux user management will change dramatically.
Change the length of Python csv strings
[Understanding in 3 minutes] The beginning of Linux
Check the behavior of destructor in Python
Script to change the description of fasta
Behavior change of [Diagram / Timeline] in Choregraphe 2.5.5.5
Change the list in a for statement
The result of installing python in Anaconda
Let's claim the possibility of pyenv-virtualenv in 2021
Change the order of PostgreSQL on Heroku
In search of the fastest FizzBuzz in Python
Change the destination batfish server of pybatfish
Visualize the export data of Piyo log
[IOS] Change the display time for each frame of GIF animation in Pythonista3.
I was in trouble because the behavior of docker container did not change
In Python, change the behavior of the method depending on how it is called
[AWS] Let's run a unit test of Lambda function in the local environment
Change Flask's log settings (dictConfig) to output logs other than the root logger
How to change the appearance of unselected Foreign Key fields in Django's ModelForm