【问题标题】:How to implement post method in serverless 1.0?如何在 serverless 1.0 中实现 post 方法?
【发布时间】:2017-05-28 22:40:31
【问题描述】:

我在 swagger 中收到“服务器无响应”错误,lambda 函数也没有触发,我在 cloudwatch 中没有看到任何错误,好像我在 post 方法中遇到了 YAML 文件的问题。 我花了 2 天时间试图了解这里发生了什么,但没有任何结果,所以我将不胜感激! 我的 yaml 文件:

pool-config:
handler: dest/functions/pool-config/handler.execute
events:
  - http:
      path: v1/config/pool
      method: post
      integration: lambda
      request:
         template:
            application/json: '{
              "body": "$input.json(''$'')",
              "functionAlias": "$stageVariables.functionAlias",
              "principalId": "$context.authorizer.principalId",
              "httpMethod": "$context.httpMethod"}'
      response:
         headers:
           Content-Type: "'application/json'"
           Access-Control-Allow-Origin: "'*'"          
         template: $input.path('$')
      cors:   
        origins:
          - '*'
        headers:
          - Content-Type 
          - X-Amz-Date
          - Authorization
      authorizer: authorizer

【问题讨论】:

    标签: amazon-web-services yaml aws-lambda


    【解决方案1】:

    我找到了答案!!!!原因是在这一行 "body": "$input.json(''$'')" 我们应该使用它而不使用像这样的引号 "body": $input.json(''$'')

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      相关资源
      最近更新 更多