繁体   English   中英

多个触发的 AWS Lambda 日志显示在单个 Cloudwatch 日志流中

[英]Multiple Triggered AWS Lambda Logs are displayed in a single Cloudwatch Log Streams

我们创建了一个 Lambda Function,它必须每分钟触发一次。 它按预期工作并显示正确的结果。 但是通过 Cloudwatch 事件获取的日志 stream 在单个 Cloudwatch 日志 stream 中包含多个 Lambda 触发日志。

活动规则:- 在此处输入图像描述

是否可以为 1 个 Lambda 触发器创建 1 个 cloudwatch 日志?

拉希特,

您的 Lambda function 附带一个 CloudWatch Logs 日志组,其中包含一个日志 stream 用于您的 ZC1C4FAB45264C1783 的每个实例。 运行时将有关每个调用的详细信息发送到日志 stream,并从您的函数代码中中继日志和其他 output。

此外,从AWS Cloudwatch 文档中,您可以看到每次日志来自不同的事件源时都会创建日志 stream。 对于 Lambda,它是每个 Lambda 容器一个 stream,其中每个容器可能处理多个事件。

日志 stream 是共享同一源的日志事件序列。 CloudWatch Logs 中的每个单独的日志源构成一个单独的日志 stream。

参考:

https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-logging.html

根据此处的 AWS Lambda 文档,日志 stream 表示您的 function 的实例 In other words, a log stream represents the logs from a single execution environment for your Lambda Function... The execution environment is also called the context (one of the arguments you can pass in to your handler) and the reason you're not每次调用都获得一个新日志 stream 是因为 Lambda 函数执行的上下文

When you invoke your Lambda function, AWS loads the container that holds your function code and provisions the requested resources that are required to enable your function to execute: CPU, memory, networking etc. These all form the functions execution environment which is also called the上下文 这些资源需要时间来配置,这会导致 function 的执行延迟增加。 这通常称为“冷启动”。

为了在每次调用时缓解这种不希望出现的延迟或冷启动,在您的 function 完成其初始执行后,AWS 不会终止执行环境,而是保持容器和执行环境的运行以及 cpu、memory 和网络等资源的运行, 为下一次调用提供并准备好并期待下一次调用。 这被称为保持 function“温暖”。 When the container is warm, subsequent invocations of your function are executed in the same execution environment, or context , as the previous invocation, and because the invocation was executed by the same instance of the function the logs are written to the same log stream as先前的调用,即日志 stream,表示 function 的实例/执行环境/上下文。

尽管如此,值得指出的是,AWS 不会让容器无限期地运行。 如果在给定时间段内没有后续调用(没有确切的时间段,但通常认为在 30 到 45 分钟之间, 来源)AWS 将终止容器,并释放资源供另一个 function 使用。 The next time the Lambda function is invoked, AWS will repeat the provisioning process for the function and a new execution environment will be created, and this will cause your functions logs to be written to a new log stream which represents the new execution environment / context / 你的 function 的实例。

您可以在此处阅读有关 Lambda 执行上下文的更多信息。

暂无
暂无

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

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