gpt4 book ai didi

amazon-web-services - AWS Lambda 和 API 网关 - 闲置;需要 "wake up"/第一次请求没有响应?

转载 作者:行者123 更新时间:2023-12-04 00:14:42 25 4
gpt4 key购买 nike

我一直在 AWS Lambda 中修改 nodejs 代码,由一些 API 网关端点调用。我注意到在没有任何 API 网关调用的情况下经过一定时间后,下一个 API 网关请求将超时。我将收到标准的 Lambda 错误消息,说明函数超时。但是,触发我的 Lambda 的后续 HTTP 请求工作正常。

从表面上看,似乎有些东西正在进入“空闲”模式,需要先充电,然后 API 网关-Lambda 请求才能正常工作。我考虑过设置一个 wget cron 来保持非空闲状态,但是否有真正的解决方法,我如何才能更好地了解正在发生的事情?

最佳答案

Lambda 使工作人员保持活跃一段时间,并会(如您所见)在一段时间不活动后移除该工作人员。以下是在 our forums 上发布的一组建议的副本:

A few suggestions:

  1. Keep your Lambda function "warm". If it's invoked infrequently you will incur an overhead "cold start" cost as Lambda needs to allocate resources to serve your request. See this post for more details.
  2. Invoke your Lambda function with resource-based permissions as opposed to role-based. This is to avoid the overhead of API Gateway needing to make an assumeRole() request to STS. Resource-based invocation is default if you set it up in the console.
  3. If appropriate, consider turning on caching for your API.
  4. Is your API doing any transformations of the request or response via mapping templates? This will obviously incur overhead linear with the complexity of the transformation.

请注意,假设其他选项均不适合您,#1 实际上只能用作最后的手段

关于amazon-web-services - AWS Lambda 和 API 网关 - 闲置;需要 "wake up"/第一次请求没有响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36268775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com