Discover how to fix issues with AWS CloudWatch alarms not provisioning correctly. Learn to reference log groups accurately in Terraform for effective monitoring. --- This video is based on the question https://stackoverflow.com/q/73736033/ asked by the user 'Alex' ( https://stackoverflow.com/u/9911723/ ) and on the answer https://stackoverflow.com/a/73778594/ provided by the user 'Alex' ( https://stackoverflow.com/u/9911723/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: AWS Cloudwatch alarm not provisioned correctly. Am I not referencing the log group to filter on correctly? Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- Understanding AWS CloudWatch Alarm Setup Issues When working with AWS CloudWatch alarms, especially when provisioning through Terraform, it's not uncommon to encounter issues. One such issue is having an alarm enter an "Insufficient Data" state, often due to incorrect log group references or misconfigurations in your Terraform scripts. In this guide, we'll discuss a typical scenario where a CloudWatch alarm fails to function correctly and provide step-by-step guidance on how to resolve it. The Problem In your case, the intention was to create a CloudWatch alarm that triggers based on specific log messages from an AWS Lambda function. While the Lambda function is working and successfully outputs messages, the alarm isn't responding as expected, indicating that it is in an "Insufficient Data" state. Possible Causes Incorrect Log Group Reference: The log group associated with the metric filter wasn't pointing to the correct log group of your Lambda function. Misaligned Metric Alarm Reference: The metrics generated by the log metric filter may not have been appropriately referenced from the metric alarm. A Closer Look at the Solution To resolve these issues, we need to ensure that our Terraform configurations correctly point to existing resources. Here's a detailed breakdown of what you need to change to align your resources correctly. 1. Correcting Log Group Reference Instead of creating a new log group in your Terraform configuration, the correct approach is to refer to the log group already in use by your Lambda function. Your current configuration incorrectly defines a new log group resource: [[See Video to Reveal this Text or Code Snippet]] This needs to be amended to directly reference the real log group. The correct log group for your Lambda function is /aws/lambda/error-test-lambda. 2. Adjusting Metric Filter Configuration In your metric filter configuration, the log group name needs to be updated to reflect this correct reference. Here’s how you can modify it: [[See Video to Reveal this Text or Code Snippet]] 3. Referring to the Metric Alarm Dynamically To ensure that the metric alarm correctly references your metric filter, adjust the parameters in your metric transformation. By doing this, you make your Terraform template more robust and easier to maintain. Here’s a recap of that change: [[See Video to Reveal this Text or Code Snippet]] Conclusion By ensuring that your Terraform configuration correctly references the existing log group associated with your Lambda function and aligning the metric alarm with the filters you’ve created, you’ll be on the path to successfully monitoring your application. Misconfigurations can often lead to frustration, but clarity and attention to detail can alleviate many headaches in infrastructure management. Happy monitoring!