简体   繁体   中英

NestJs on AWS Lambda Endpoint request timed out

I have a Nest.js' application hosted on AWS Lambda using serverless cli.

when I try access the endpoint I receive {"message": "Endpoint request timed out"}. I tried to increase the time but the error persists.

How I can solve this?

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

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. It means The API gateway cannot wait more than 29 seconds for the lambda to return.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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