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?

2 réponses
0
Réponse acceptée

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
répondu il y a 2 ans
  • 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
répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions