retention_in_days

Type number
Default 30

Number of days to retain log events in the log group. Set to 0 for indefinite retention.

Example

retention_in_days = 30

Retention Options

CloudWatch Logs supports specific retention periods. The default is 30 days.

DaysUse Case
1, 3, 5, 7, 14Development/debugging
30, 60, 90Standard application logs
120, 150, 180Compliance requirements
365Annual audit requirements
400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, 3653Long-term retention
0 (null)Never expire

Cost Considerations

  • Longer retention periods increase storage costs
  • Consider archiving to S3 for long-term storage
  • Use subscription filters to export logs before expiration

Best Practices

  • Set retention based on compliance requirements
  • Use shorter retention for high-volume debug logs
  • Consider cost vs. troubleshooting needs
  • Document retention decisions for audit purposes

Full Module Example

module "cloudwatch_logs" {
  source  = "registry.patterneddesigns.ca/essentials/cloudwatch-logs/aws"
  version = "1.0.0"

  # retention_in_days
  retention_in_days = 30

  # Other required inputs
  log_group_name = "/aws/lambda/my-function"
}