amazon-web-services - AWS Lambda : Identifying cold starts

标签 amazon-web-services aws-lambda serverless cold-start

是否有明确的方法来识别“冷启动”?是在 Lambda 本身的运行时,还是通过日志?我知道冷启动的特点是运行时间更长,我实际上可以看到,但我正在寻找一种明确的方法。
如果这很重要,我正在使用 Node.js。

更新:下面有两个很好的答案,适用于两个用例:
- 在 lambda 运行时识别冷启动。
- 从 CloudWatch 日志中识别冷启动。

最佳答案

如果您在 NodeJS 脚本的顶部添加一些初始化代码,您将能够在代码中指出这是一个冷启动,然后如果您想在日志中看到它,您将能够记录它。例如:

var coldStart = true;
console.log("This line of code exists outside the handler, and only executes on a cold start");


exports.myHandler = function(event, context, callback) {
  if (coldStart) {
    console.log("First time the handler was called since this function was deployed in this container");
  }
  coldStart = false;

   ...
   
  callback(...);
}

更新:
如果您只关心在日志中看到冷启动,Lambda 现在会记录额外的 “初始化持续时间” CloudWatch Logs 中冷启动的值。

关于amazon-web-services - AWS Lambda : Identifying cold starts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47061146/

相关文章:

amazon-web-services - 运行放大模拟时无法访问 DynamoDB 主机

google-app-engine - 何时选择 App Engine 而不是 Cloud Functions?

php - 适用于 PHP 的 AWS 开发工具包 : Error retrieving credentials from the instance profile metadata server

ios - 如何避免在 Cognito 联合身份中创建未使用的身份

amazon-web-services - 如何从 aws cloudwatch 自定义指标中删除维度

node.js - 对于 AWS lambda 无服务器 nodejs 应用程序,您如何在开发环境中执行请求?

amazon-web-services - AWS 在多个安全组中重用 IP

amazon-web-services - AWS API 网关 :

amazon-web-services - 如何找出对我的调用计数/成本有贡献的 lambda