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 年前檢視次數 1944 次
2 個答案
0
已接受的答案

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
已回答 2 年前
  • 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
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南