简体   繁体   English

将多个日志组添加到 Cloudwatch 事件触发器而无需单独指定它们?

[英]Adding multiple log groups to Cloudwatch event triggers without having to specify them individually?

I would like to trigger a Lambda function on error events generated from my other Lambda functions.我想在我的其他 Lambda 函数生成的错误事件上触发 Lambda function。 I see it is possible to add multiple log groups using Serverless.我看到可以使用无服务器添加多个日志组。 Example from here .示例来自这里

functions:
  hello1:
    handler: handler.hello1
    events:
      - cloudwatchLog: '/aws/lambda/hello1'
  hello2:
    handler: handler.hello2
    events:
      - cloudwatchLog: '/aws/lambda/hello2'

however that means defining an event + filter for each function (I have about 2 dozen) and this would need to be updated for any additional functions I add in the future.然而,这意味着为每个 function (我有大约 2 打)定义一个事件 + 过滤器,这需要为我将来添加的任何其他功能进行更新。 Is there any way to use a catch-all log group definition like /aws/lambda/* ?有没有办法使用像/aws/lambda/*这样的包罗万象的日志组定义?

I already set up a Cloudwatch alarm using a metric filter for the aws/lambda namespace with the Errors metric.我已经使用带有Errors指标的aws/lambda命名空间的指标过滤器设置了 Cloudwatch 警报。 Easy and done, however the SNS topic it publishes contains little information regarding the nature of the error.简单易行,但是它发布的 SNS 主题几乎没有关于错误性质的信息。 I want to create a Lambda function that publishes an SNS topic directly that includes the stack trace.我想创建一个 Lambda function 直接发布包含堆栈跟踪的 SNS 主题。 I'm hoping it would be as easy to select-all log groups in the same way.我希望以同样的方式选择所有日志组也一样容易。

You would need an architectural change.您需要进行架构更改。

Create a Kinesis data stream and subscribe individual cloudwatch log groups to that single kinesis stream创建 Kinesis 数据 stream 并将各个 cloudwatch 日志组订阅到该单个 kinesis stream

The lambda that processes the error logs needs to have Kinesis as event source.处理错误日志的 lambda 需要将 Kinesis 作为事件源。

This would now enable triggers from the kinesis for logs from any of the lambda functions' cloudwatch log groups现在,这将为来自任何 lambda 函数的 cloudwatch 日志组的日志启用来自 kinesis 的触发器

To enable this subscription automatically, use serverless itself with Kinesis CloudWatch subscription and the kinesis stream is going to be same for all functions.要自动启用此订阅,请将无服务器本身与 Kinesis CloudWatch 订阅结合使用,并且所有功能的 kinesis stream 将相同。

Serverless has a plugin to do the same (serverless-plugin-log-subscription) https://www.serverless.com/plugins/serverless-plugin-log-subscription Serverless 有一个插件可以做同样的事情(serverless-plugin-log-subscription) https://www.serverless.com/plugins/serverless-plugin-log-subscription

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM