CodeBuild Logs Config - CloudWatch supports Time-based log retention.
For CodeBuild logs - Can we achieve Log Retention which says like - "Retain the latest 3 Successful build logs" + "Retain the latest 3 Failed build logs" ?
CodeBuild Logs Config - CloudWatch supports Time-based log retention.
For CodeBuild logs - Can we achieve Log Retention which says like - "Retain the latest 3 Successful build logs" + "Retain the latest 3 Failed build logs" ?
In my case I use this method:
.tf I created the resource loggroup with retention:resource "aws_cloudwatch_log_group" "loggroup" {
name = "/aws/codebuild/test"
retention_in_days = 30
}
logs_config {
cloudwatch_logs {
group_name = aws_cloudwatch_log_group.loggroup.name
}
}
And then I apply my terraform code.
More for future reference here on how to configure time-based retention periods in CloudFormation since there is already a TerraForm example :
AWSTemplateFormatVersion: "2010-09-09"
Resources:
# CodeBuild
# ------------------------------------------------------------
CodeBuildProject:
Type: AWS::CodeBuild::Project
# Logs
# ------------------------------------------------------------
LogsLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/codebuild/${CodeBuildProject}"
RetentionInDays: 7
If you want to retain loggroups like you asked you'd have to do it yourself with a Lambda function.