How do I use log rotation with CloudWatch Agent?

1 minuto de leitura
0

I want to use log rotation with Amazon CloudWatch Agent to delete log files after I upload content to Amazon CloudWatch Logs.

Resolution

To turn on log rotation, update the auto_removal parameter within the logs section of the agent's configuration file to true:

Note: Replace example-instance-id with the required instance ID.

"logs":
   {
   "logs_collected": {
     "files": {
     "collect_list": [
       {
       "file_path": "/var/log/myapp/myapp.log"",
       "log_group_name": "MyAppLogs",
       "log_stream_name": "{example-instance-id}",
       "auto_removal": true
       }  
     ]
     }
   }
  }

Note: The agent only removes complete files from logs that create multiple files, such as logs that create separate files for each date. If a log continuously writes to a single file, then it's not removed. For more information, see CloudWatch agent configuration file: Logs section.

AWS OFICIAL
AWS OFICIALAtualizada há 7 meses