Avatar of the person chatting

In the AWS Cloud Watch, I see some error messages starting with [ERROR]. When I get such message, I'd like to get an email or something. Can you help me on that? -- START RequestId: 3d3ed561-0633-4d37-9dd2-305ed289b916 Version: $LATEST 2023-01-23T08:40:51.402+09:00 [ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_main': No module named 'credit_check' Traceback (most recent call last): 2023-01-23T08:40:51.403+09:00 END RequestId: 3d3ed561-0633-4d37-9dd2-305ed289b916 2023-01-23T08:40:51.403+09:00 REPORT RequestId: 3d3ed561-0633-4d37-9dd2-305ed289b916 Duration: 1.80 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 68 MB Init Duration: 463.00 ms 2023-01-23T08:40:51.841+09:00 START RequestId: aca56834-5aeb-4e89-8c94-7bb07c9d91f6 Version: $LATEST 2023-01-23T08:40:51.841+09:00 [ERROR] Runtime.ImportModuleError: Unable to import module 'lam

AWS CloudWatch allows you to set up alarms that can notify you when certain conditions are met, such as when a metric goes above or below a specified threshold, or when a pattern is detected in a log stream. To set up an alarm that will notify you when an error message is logged, you can do the following:

  1. Go to the CloudWatch console and select Alarms from the navigation menu.
  2. Click on the Create alarm button.
  3. Select the metric that you want to use for the alarm, in this case, it would be the error message.
  4. Set the alarm condition, such as when the error message appears more than x times in y minutes
  5. Select the actions that should be taken when the alarm is triggered, such as sending an email or SMS message, or triggering an AWS Lambda function.
  6. Give a name to the alarm and click on the create alarm button.

You can also set up CloudWatch Event rule to trigger Lambda function or SNS topic, when error message appears in the CloudWatch logs.

Avatar of the person chatting

In this case, I want to capture [ERROR] message. Can you help me on that?

Yes, you can capture [ERROR] messages in CloudWatch Logs by setting up a CloudWatch Logs subscription filter. Here's how you can do it:

  1. Go to the CloudWatch Logs console and select the log group that you want to subscribe to.
  2. Click on the "Create Subscription Filter" button.
  3. Choose the "Filter Pattern" option and enter the pattern that you want to use to capture the error messages. In this case, it would be [ERROR].
  4. Choose the destination for the captured logs. It could be another CloudWatch log group, a Lambda function, an Elasticsearch domain, or a Kinesis Data Stream.
  5. Give a name to the subscription filter and click on the "Create Subscription Filter" button.

With this setup, CloudWatch will send all logs matching the filter pattern to the specified destination. You can also set up Alarm on that destination log stream, like I mentioned earlier, to notify you when error message appears.