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개 답변
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠