Implementing Long-Term CloudWatch Log Retention Using Terragrunt

Implementing Long-Term CloudWatch Log Retention Using Terragrunt

Introduction:-

#AmazonCloudWatch Logs is a managed service for storing, searching, and analyzing log data. A log group is a collection of log streams with shared settings. You can configure #retention, #encryption, and access control settings when creating a log group. #CloudWatch Logs helps troubleshoot issues, monitor resource utilization, and generate metrics and alarms based on log data. Logs can be exported to #Amazon S3 or Amazon #Elasticsearch for further analysis and visualization.

  • Pre-Requestisites :-

  • An AWS account with appropriate permissions to create resources like cloud watch lag groups and #Terraform access.

  • #Terragrunt installed on your local machine.

  • Basic knowledge of AWS.

Step-1:- create a folder named cloud watch in your home directory and within that folder create a file called terragrunt.hcl

Step-2 :- write a terragrunt code to create a cloud watch lag group.

This is an example reference.

$terragrunt.hcl

terraform {
  source  = "tfr:///terraform-aws-modules/cloudwatch/aws?version=4.2.1"

}
include "root" {
 path = find_in_parent_folders()
}
locals {
 region        = "us-east-1"
}

inputs = {
  name              = "my-log-group"
  retention_in_days = 365
}

After paste this code in the file .Just save and open the terminal enter the first command terragruntinit for Initializing and after Initialization, enter the second command terragruntplan when the plan executed successfully ,enter the third command terragruntapply after apply configuration would be done in your aws cloudwatch console.

As You can Follow the below step by step process to get it done manually :

To change the logs retention setting.

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. In the navigation pane, choose #Log groups.

  3. Find the log group to update.

  4. In the Expire Events After column for that log group, choose the current retention setting, such as Never Expire.

  5. In Edit Retention, for #Retention, choose a log retention value, and then choose Ok.

Conclusion:-

#CloudWatch log groups provide a way to organize and manage log streams with shared settings. They enable you to configure retention, #encryption, and access control settings, and can be used for #troubleshooting, #monitoring, and generating metrics and alarms. #CloudWatch Logs also supports exporting logs to Amazon S3 or #Amazon Elasticsearch for further #analysis and #visualization.