【问题标题】:Configuring AWS::Serverless::Api resources for HTTP_PROXY integration为 HTTP_PROXY 集成配置 AWS::Serverless::Api 资源
【发布时间】:2019-11-11 22:58:31
【问题描述】:

使用控制台,我能够配置 API 网关方法,将带有路径参数的 HTTP 请求传递到另一个 URI。

结果如下

这样可以将我的请求转发到https://example.com,并使用相同的(贪婪)路径参数。

虽然这已经足够成功,但我需要能够在 cloudformation 模板中将其指定为 AWS::Serverless::Api 资源。据我所知,the documentation for the Serverless Application Model 没有提及如何实现这一点。

可以在无服务器资源上完成,还是我需要使用传统的 AWS::ApiGateway::Resource/Method's?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation aws-api-gateway aws-serverless serverless-application-model


    【解决方案1】:

    我找到的最简单的方法是使用DefinitionBody 创建一个大摇大摆的定义,这里有一个例子,所以你可以得到一个想法。 Repo

    重要提示:如果您在 Lambda 上使用代理集成,则 x-amazon-apigateway-integration 中的 httpMethod 方法应为 POST,无论您的方法是 GETPUTPOST 还是DELETE => httpMethod: POST

    DefinitionBody: 
        swagger: 2.0
        info:
          title: EventSource API Definition
        paths:
          /events/{id}:
            get:
              summary: Get an event details
              description: Retrieve specific event
              parameters:
              - name: id
                in: path
                required: true
                type: string
              consumes:
                - application/json
              produces:
                - application/json
              x-amazon-apigateway-integration:
                uri:                  
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetEventsFunction.Arn}/invocations
                responses: {}
                httpMethod: POST
                type: aws_proxy
    

    【讨论】:

    • httpMethod: POST 的要求不是仅用于 lambda 代理集成吗?
    • Brody 要求 http_proxy 集成,这是 aws_proxy 集成
    猜你喜欢
    • 2017-12-09
    • 2018-09-28
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 2020-03-10
    • 1970-01-01
    相关资源
    最近更新 更多