Skip to main content

CloudWatch Log Group

πŸ“¦ Overview​

This Terraform module provisions an Amazon CloudWatch Log Group with customizable retention and tagging settings.

It’s ideal for ingesting logs from AWS services, Lambda functions, ECS tasks, and custom applicationsβ€”forming the foundation for observability pipelines.


βœ… Key Features​

  • Creates a CloudWatch Log Group with a custom name
  • Configures retention period in days (default or user-defined)
  • Adds environment-based tags for traceability
  • Supports centralized logging and compliance alignment

πŸ’Ό Use Cases​

  • Logging Lambda, ECS, or EC2 output in structured format
  • Managing audit and access logs for compliance
  • Grouping logs by environment (e.g., /app/dev, /prod/api)
  • Building metrics and alarms on log filters

πŸ“₯ Input Variables​

NameTypeDescription
regionstringAWS region to deploy the log group
log_group_namestringName of the CloudWatch Log Group
retention_in_daysnumberNumber of days to retain logs (e.g., 7, 30, 365)
environmentstringTag to specify the deployment environment (e.g., dev, staging, prod)

πŸ“€ Outputs​

NameDescription
log_group_nameThe name of the provisioned log group
log_group_arnThe ARN of the provisioned log group

πŸš€ Deployment Readiness​

  • βœ… Compatible with Terraform 1.0+
  • βœ… Tested with AWS provider 5.x
  • πŸ§ͺ Requires IAM permissions to create and manage CloudWatch resources

πŸ› οΈ Example Usage​

module "cloudwatch-log-group-deployment" {
source = "git::ssh://git@github.com/archiphire/aws-level-1-modules.git//monitoring/cloudwatch-log-group?ref=v1.0.0"

region = "us-east-1"
log_group_name = "/app/env/service-logs"
retention_in_days = 30
environment = "prod"
}
terraform init
terraform plan
terraform apply

or

tofu init
tofu plan
tofu apply

🧹 Cleanup Options​

terraform destroy

or

tofu destroy

Manual Deletion (production):

aws logs delete-log-group --log-group-name /app/env/service-logs

πŸ›‘οΈ Notes​

This is a Level 1 monitoring module designed for flexible log ingestion. For enhanced observability, pair it with:

cloudwatch-alarm-cpu cloudwatch-dashboard-basic

πŸ”’ Deployment Package Notice​

This module is part of the Level 1 AWS License Tier. To access the full deployment package and source code, subscribe to Archiphire.