【问题标题】:Lambda is returning headers in body of requestLambda 在请求正文中返回标头
【发布时间】:2020-08-08 00:40:02
【问题描述】:

我正在使用无服务器在 lambda 中部署我的 express js 应用程序。奇怪的是,一些 api 在响应正文中返回标头,我不确定为什么会这样。这是我的无服务器 YAML 文件:

org: test
app: test-api
# serverless.yml
service: test-api

package:
  exclude:
   #- node_modules/**
   - __tests__/**

provider:
    name: aws
    runtime: nodejs10.x
    region: us-east-1
    environment:
        SERVICE_NAME: ${self:service}

plugins:
  - serverless-domain-manager

custom:
  stage: ${opt:stage, dev}
  domains:
    prod: api.test.com
    dev: dev-api.test.com

  customDomain:
    basePath: "${self:provider.environment.SERVICE_NAME}"
    domainName: ${self:custom.domains.${self:custom.stage}}
    stage: "${self:custom.stage}"
    createRoute53Record: true

functions:
  test-api:
    handler: build/app.handler
    environment:
        stage: ${self:custom.stage}
    events:
      - http:
          path: v1/s
          method: GET
          cors: true
      - http:
          path: v1/sc
          method: GET
          cors: true
      - http:
          path: v1/s/{s}
          method: GET
          cors: true
      - http:
          path: v1/cs
          method: POST
          cors: true
      - http:
          path: v1/s
          method: POST
          cors: true
      - http:
          path: v1/s/{s}
          method: DELETE
          cors: true
      - http:
          path: v1/s/{s}
          method: PUT
          cors: true

下面是响应的样子:

curl -d '{"c":"test"}' -H "Content-Type: application/json" -X POST https://dev-api.test.com/test-api/v1/cs

HTTP/1.1 200 Not Modified
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: sessionId
Vary: Origin
Content-Type: application/json; charset=utf-8
Content-Length: 55
ETag: W/"37-vmzwGqI9Wb8ACGS7qhhE3/JBqt4"
Date: Fri, 24 Apr 2020 12:30:41 GMT
Connection: keep-alive

{"rsp":{"msg":{"s":[],"c":{}},"err":null}

知道是无服务器 yaml 还是其他配置?

【问题讨论】:

  • 对此有什么想法吗?
  • 除非您更改 api 网关上的集成响应中的某些内容,否则此配置应使用正文中的标头进行响应。但是我还是不明白你指的是什么标题?至少您分享的内容看起来像正常的 curl 响应

标签: express curl aws-lambda serverless-framework


【解决方案1】:

我能够解决这个问题,联系了无服务器支持,他们说存在错误,现在已经修复。只需更新 serverless 即可解决!

【讨论】:

    【解决方案2】:

    您好像启用了curl 的-i 选项? curl 有别名吗?

    【讨论】:

      猜你喜欢
      • 2014-08-04
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 2018-09-22
      相关资源
      最近更新 更多