簡體   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