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 年前1946 查看次数
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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则