无服务器AWS ApiGateway方法响应

时间:2019-10-25 13:03:30

标签: aws-api-gateway serverless aws-serverless

我对无服务器和API网关有疑问

我的serverless.yml中有一个这样的函数:

getAccount:
handler: functions/account/handlers.getAccount
events:
  - http:
      path: account
      method: get
      cors: true
      authorizer: authorize

但是我需要通过API网关接口添加一些内容: API Gateway expected

我想用类似的东西将其直接添加到我的无服务器文件中

getAccount:
handler: functions/account/handlers.getAccount
events:
  - http:
      path: account
      method: get
      cors: true
      authorizer: authorize
methodresponse:
      code : 200
      header : "Access-Control-Allow-Origin"
      body :
            content-type : "application/json"
            model : Empty

有人可以告诉我serverless.yml将该文件添加到我的文件中的语法吗?

谢谢

1 个答案:

答案 0 :(得分:0)

请在下面的Serverless中找到Method Responses的示例代码。 请让我知道你的情况。

    getAccount:
    handler: functions/account/handlers.getAccount
    events:
      - http:
          path: account
          method: get
          cors: true
          authorizer: authorize         
          methodResponses:
            -
              statusCode: "200"
              responseBody:
                description: "Response body description"
              responseHeaders:
                -
                  name: "x-superheader"
                  description: "this is a super header"
              responseModels:
                "application/json": "CreateResponse"
            -
              statusCode: "400"
              responseModels:
                "application/json": "ErrorResponse"
相关问题