【问题标题】:NestJs on AWS Lambda Endpoint request timed outAWS Lambda Endpoint 上的 NestJs 请求超时
【发布时间】:2020-05-28 10:32:17
【问题描述】:

我使用无服务器 cli 在 AWS Lambda 上托管了一个 Nest.js 应用程序。

当我尝试访问端点时,我收到 {"message": "Endpoint request timed out"}。我尝试增加时间,但错误仍然存​​在。

我该如何解决这个问题?

serverless.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

【问题讨论】:

    标签: amazon-web-services aws-lambda graphql timeout nestjs


    【解决方案1】:

    它对你不起作用的原因是,即使 lambda 支持长达 15 分钟的时间输出,API 网关也有 29 秒的限制。这意味着 API 网关等待 lambda 返回的时间不能超过 29 秒。

    如果你需要超过 29 秒,你应该考虑通过其他一些不涉及 API 网关的机制来开发 API,例如 express 框架。

    我建议您首先尝试找出代码的哪一部分需要更长的执行时间。在寻找替代方案之前,您可以尝试优化代码。

    希望这会有所帮助。

    参考:

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

    【讨论】:

      猜你喜欢
      • 2021-07-23
      • 2021-02-28
      • 2018-08-17
      • 2019-10-06
      • 1970-01-01
      • 2019-02-07
      • 2019-11-15
      • 2020-11-16
      相关资源
      最近更新 更多