ECS Fargate Log Configuration - How to set the retention policy?

0

I have been using ECS Fargate to launch containers that are designed to execute some tasks and terminate once done. In the task definition, I have given awslogs as the logDriver and awslogs-create-group set to true so that each time it creates a log group in CloudWatch. But I notice in CW that the retention policy of the log groups is set to 'Never Expire', and over time there are many log groups that simply exist even though the cluster behind it are terminated. How can I ensure that the log groups are deleted as soon as the Fargate cluster/task is terminated?

preguntada hace 2 años1947 visualizaciones
2 Respuestas
0
Respuesta aceptada

Hi, Good question

I think you can use

 put-retention-policy
--log-group-name <value>
--retention-in-days <value>
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]

https://docs.aws.amazon.com/cli/latest/reference/logs/put-retention-policy.html

profile picture
Sri
respondido hace 2 años
  • Thanks! So there is no way that I can set this policy from task definitions?

  • I think It can only be done through CloudWatch. Docker has the following options and I can't seem to find anything related to retention

    max-size - The maximum size of the log before it is rolled. A positive integer plus a modifier representing the unit of measure (k, m, or g). Defaults to 20m.
    max-file - The maximum number of log files that can be present. If rolling the logs creates excess files, the oldest file is removed. A positive integer. Defaults to 5.
    compress - Toggle compression of rotated log files. Enabled by default.
    

    https://docs.docker.com/config/containers/logging/local/

0

Actually, you can create LogGroup yourself and attach it to the Task Definition like here if you are using CloudFormation.

Then in LogGroup, you can simply set retention and another benefit is that LogGroup will be removed together with CloudFormation stack.

profile picture
MG
respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas