意外的 LAMBDA_RUNTIME 无法发布处理程序成功响应。 HTTP 响应代码:413 错误

问题描述 投票:0回答:2

所以我有一个在 Lambda 中运行的无服务器 Express 应用程序。一个请求(响应大小约为 800KB)不断返回

LAMBDA_RUNTIME Failed to post handler success response. Http response code: 413.
错误。 我认为这可能是由于某些内部逻辑超时,并添加了日志,并且所有获取和处理最多需要 6 秒,但 lamdba 仍然返回此错误。

这些是响应标头

x-amz-cf-pop: YTO50-C3
x-amzn-errortype: InternalServerErrorException
x-amzn-requestid: f291230-342-4324-324-cb7df188944c
x-cache: Error from cloudfront

响应大小绝对不会太大,我返回带有正确数据的响应,日志中没有抛出任何错误。知道为什么会发生这种情况吗?另外关于如何调试这个问题有什么建议吗?当然,一切都可以在本地运行,但是有没有办法让我调试实际的 lambda?我添加的日志表明整个过程已完成,但不知何故返回了错误。

更新了我的 serverless.yml 配置

service: my-service
variablesResolutionMode: 20210326
useDotenv: true

custom:
  serverless-offline:
    useChildProcesses: true
  webpack:
    webpackConfig: ./webpack.config.js
    packager: "yarn"
    includeModules: true
  prune:
    automatic: true
    includeLayers: true
    number: 3
  customDomain:
    domainName: "abc.com"
    basePath: "val"
    stage: ${someval}
    createRoute53Record: true

plugins:
  - serverless-domain-manager
  - serverless-webpack
  - serverless-prune-plugin
  - serverless-webpack-prisma
  - serverless-offline

provider:
  lambdaHashingVersion: "20201221"
  name: aws
  runtime: nodejs14.x
  region: us-east-1
  timeout: 30
  apiGateway:
    minimumCompressionSize: 1024 
  iamRoleStatements:
    - Effect: Allow
      Action: ssm:Get*
      Resource:
        - "abc/${opt:stage}/backend/*"
        - "abc/${opt:stage}/services/*"
    - Effect: Allow
      Action: kms:Decrypt
      Resource: "*"
    - Effect: "Allow"
      Action: s3:PutObject
      Resource: "abc/*"
    - Effect: "Allow"
      Action:
        - sns:Publish
      Resource: "*"

  environment:
    - myvars: 'abc'

functions:
  graphql:
    handler: src/index.graphqlHandler
    events:
      - http:
          path: /graphql
          method: options
      - http:
          path: /graphql
          method: get
      - http:
          path: /graphql
          method: post
amazon-web-services express aws-lambda graphql serverless
2个回答
21
投票

此错误通常是由于达到了响应负载的 Lambda 限制。

目前,AWS Lambda 对以下调用负载有硬性限制:

  • 6MB 用于同步请求和
  • 256KB 用于异步请求,

根据文档: https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html

请记住,这是一个硬性限制,无法增加。

目前(2022年),如果您需要超过此限制,您将有我能想到的两种选择

  1. 使用其他堆栈,例如 ECS
  2. 您可以在 lambda 中压缩(gzip、brotli 等)您的响应并在消费者中解压缩。如果您使用 API Gateway 公开 lambda,则必须设置适当的标头。
  3. 就我个人而言,甚至在达到此阈值之前我就遇到过类似的问题,因此很难准确计算有效负载的大小。


0
投票

https://docs.aws.amazon.com/firehose/latest/dev/data-transformation.html

© www.soinside.com 2019 - 2024. All rights reserved.