【问题标题】:API Gateway SAM specify HTTP GET: 500 Internal Server ErrorAPI Gateway SAM 指定 HTTP GET:500 内部服务器错误
【发布时间】:2018-10-25 12:55:48
【问题描述】:

当我尝试调用我使用 SAM 定义的 GET 端点时,我总是得到一个 500 Internal Server Error

我能够定义一个有效的 POST 请求。 对于 GET 请求,它向我显示: Lambda invocation failed with status: 403 Execution failed due to configuration error:

我认为我定义 API 网关的 DefinitionBody 的地方有问题。

Globals:
  Api:
    Cors:
      AllowMethods: "'GET,POST,OPTIONS'"
      AllowHeaders: "'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'"
      AllowOrigin: "'*'"
Resources:
  getFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      ...
      Events:
        GetApi:
          Type: Api
          Properties:
            Path: /tips
            Method: GET
            RestApiId: !Ref MyApi
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: dev
      EndpointConfiguration: REGIONAL
      DefinitionBody:
        swagger: "2.0"
        info:
          title: "API"
        paths:
          /tips:
            get:
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${getFunction.Arn}/invocations
                responses: {}
                httpMethod: "POST"
                type: "aws_proxy"

我已经尝试将 x-amazon-apigateway-integration 上的 httpMethod 更改为“GET”,但这并不能解决我的问题。

在 AWS Lambda 控制台中,我看到 Lambda 和 Api Gateway 已链接,但我无法通过 API Gateway 调用 Lambda。我可以使用控制台中的测试事件成功执行我的 Lambda。这绝对是 API 网关方面的东西。

谁能验证我做错了什么?

【问题讨论】:

    标签: amazon-web-services aws-api-gateway sam


    【解决方案1】:

    进一步挖掘后,我发现我必须像这样实现/tips路径的GET方法:

            get:
              responses:
                '200':
                  description: 200 response
                  headers:
                    Content-Type:
                      type: string
              produces:
              - application/json
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${getTipsFunction.Arn}/invocations"
                passthroughBehavior:  when_no_match
                responses:
                  default:
                    statusCode: 200
                    responseParameters:
                      method.response.header.Content-Type: integration.response.header.content-type
                httpMethod: POST
                type: aws
    

    这样就解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-16
      • 2012-02-23
      • 1970-01-01
      相关资源
      最近更新 更多