amazon-web-services - Can AWS email errors logged to CloudWatch by multiple Lambda functions?
问题描述
I have many functions in AWS Lambda that are invoked on various periodic schedules by CloudWatch Rules. If their Node JavaScript encounters an error, it’s logged to CloudWatch Log Groups.
- Per this doc, I can create a CloudWatch Simple Notification Service (SNS) to email me.
- Per this doc, I can create a CloudWatch Metric to count occurrences of the word
ERROR
in a single Log Group. - Per this doc, I can create a CloudWatch Alarm that uses the SNS to email me when a single Metric is observed.
Can either or both of these two complaints be solved by these tools, or should other tools be used?
- The received email is generic. Can it include the error message?
- This works for only one Lambda function’s one Log Group. Can it be configured to work for multiple Lambda functions’ Log Groups? Can my multiple Lambda functions be configured to log to a single, shared Log Group? Or would I need to create a pair of Metrics and Alarms for each Lambda function?
解决方案
TL;DR this is the solution architecture you're probably looking for.
(source: Amazon)
Can my multiple Lambda functions be configured to log to a single, shared Log Group?
No. Even if you could have all your lambda log to a single log group, however, this would be highly inadvisable.
You could, however, stream multiple log groups into a single destination. This is commonly done for centralized logging solutions, for example.
would I need to create a pair of Metrics and Alarms for each Lambda function?
This is probably the most straightforward approach. Using CloudFormation (or related tools, AWS CDK, Terraform, etc) you can automate this setup with the creation of your lambda function.
The received email is generic. Can it include the error message?
Not easily. The CloudWatch Alarm event source won't include any reference to the logs that caused the count metric to go into alarm, so this would not work. Usually, when you receive such an alert, you would use other services to find the errors (e.g. xray, cloudwatch logs, etc). For example, your message may simply include a link to the CloudWatch metric/alarm. From CloudWatch, there should be a 'view logs' button that provides the logs for the metric timeframe. See: Pivot from metrics to logs
If you really need the error to be contained in the notification, a different solution architecture would be needed for this. You could, for example, stream your CloudWatch events to a Lambda function that will process the event and send the notification including the error message from the stream.
See: Real-time processing of log data with subscriptions and How to get notified on specific Lambda function error patterns using CloudWatch which has a full guide to getting your error message in your notifications.
Alternatively, you may want to consider other monitoring solutions, such as sentry, rollbar, NewRelic, DataDog, etc.
推荐阅读
- google-maps - 嵌入谷歌地图时如何将一个地方显示为活动?
- c# - 在 List 中创建新的模型数组
包含每四个索引中的值 - r - cudNN lstm的GPU内存使用和加速
- python-3.x - 需要从 2 个日历函数中获取值,找到差异并将其存储在标签小部件中
- javascript - Python Selenium:单击带有 JavaScript onFocus 验证的按钮
- tensorflow - 在基本的 Mnist keras 示例中,所有权重都变为 NaN
- python-3.x - 非法指令4(把python安装弄得一团糟,不知道我在做什么)
- android - 在我的手机上显示图像时出现问题,但图像在 Android Emulator 上显示良好
- ruby-on-rails - Rails:如何在没有 N+1 查询的情况下急切加载有限的有序关联记录
- java - 将两种不同数据类型的数组列表合并到一个数组列表中