简体   繁体   English

AWS Lambda Endpoint 上的 NestJs 请求超时

[英]NestJs on AWS Lambda Endpoint request timed out

I have a Nest.js' application hosted on AWS Lambda using serverless cli.我有一个使用无服务器 cli 托管在 AWS Lambda 上的 Nest.js 应用程序。

when I try access the endpoint I receive {"message": "Endpoint request timed out"}.当我尝试访问端点时,我收到 {"message": "Endpoint request timed out"}。 I tried to increase the time but the error persists.我试图增加时间,但错误仍然存​​在。

How I can solve this?我该如何解决这个问题?

serverless.yml无服务器.yml

  name: aws
  runtime: nodejs12.x
  stage: prod
  profile: default # Config your AWS Profile
  timeout: 120
  environment: # Service wide environment variables
    NODE_ENV: production

plugins:
  - serverless-offline
  - serverless-plugin-warmup

custom:
  # Enable warmup on all functions (only for production and staging)
  warmup:
    enabled: true

package:
  exclude:
    - .git/**
    - src/**
    - test/**
    - nodemon.json
    - README.md
  excludeDevDependencies: true

functions:
  index:
    handler: dist/serverless.handler
    events:
      - http:
          cors: true
          path: '/graphql'
          method: any

The reason why it does not work for you is, even though the lambda supports up to 15 minutes time output, the API gateway has a limit of 29 seconds.它对您不起作用的原因是,即使 lambda 支持最多 15 分钟的时间输出,API 网关也有 29 秒的限制。 It means The API gateway cannot wait more than 29 seconds for the lambda to return.这意味着 API 网关不能等待 lambda 返回超过 29 秒。

If you need more than 29 seconds, You should consider developing the API through some other mechanism that does not involve an API gateway such as express framework.如果您需要超过 29 秒,您应该考虑通过其他一些不涉及 API 网关的机制(例如 express 框架)来开发 API。

I would suggest that you should first try and find out which part of the code takes longer to execute.我建议您首先尝试找出代码的哪一部分执行时间更长。 You can try and optimize the code before going for alternatives.在寻找替代方案之前,您可以尝试优化代码。

Hope this helps.希望这可以帮助。

Reference:参考:

https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html

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

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