我正在使用带有 Lambda 函数的 API 网关创建我的应用程序的后端,但我遇到了请求的响应时间问题。
众所周知,Lambda 函数有臭名昭著的“冷启动”,好吧,我们已经接受了。但我遇到的问题似乎是一个新的冷启动,这次是通过 API Gateway。ms
而且待机时间也不多,是seconds
(12-15秒左右)。天哪,这是个大问题……
这种响应延迟在第一次请求时会出现 12-15 秒,并且会在一些不活动之后(大约 1 小时)发生。
我的问题是:什么可能导致这种延迟以及如何解决它?
更多信息:
我的 lambda 函数配置为在 VPC 上运行。
来自 API Gateway 的 CloudWatch 日志:
(01) Extended Request Id: XXXXX=
(02) Verifying Usage Plan for request: XXXXX. API Key: API Stage: XXXXX
(03) API Key authorized because method 'GET /XXXXX' does not require API Key. Request will not contribute to throttle or quota limits
(04) Usage Plan check succeeded for API Key and API Stage XXXXX/v1
(05) Starting execution for request:
(06) HTTP Method: GET, Resource Path:
(07) Method request path:
(08) Method request query string:
(09) Method request headers:
(10) Method request body before transformations:
(11) Endpoint request URI:
(12) Endpoint request headers:
(13) Endpoint request body after transformations:
(14) Sending request to XXXXX
(15) Received response. Integration latency: 14497 ms
(16) Endpoint response body before transformations:
(17) Endpoint response headers:
(18) Method response body after transformations:
(19) Method response headers:
(20) Successfully completed execution
(21) Method completed with status: 200
(22) AWS Integration Endpoint RequestId :
(23) X-ray Tracing ID :