retention_in_days
Number of days to retain log events in the log group. Set to 0 for indefinite retention.
Example
retention_in_days = 30Retention Options
CloudWatch Logs supports specific retention periods. The default is 30 days.
| Days | Use Case |
|---|---|
| 1, 3, 5, 7, 14 | Development/debugging |
| 30, 60, 90 | Standard application logs |
| 120, 150, 180 | Compliance requirements |
| 365 | Annual audit requirements |
| 400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, 3653 | Long-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"
}