通过Cloudformation在AWS API网关上设置HTTP代理

时间:2017-08-18 11:36:56

标签: azure amazon-web-services yaml aws-api-gateway azure-api-management

感谢您的帮助。

目前使用云形态模板将一个简单的API部署到AWS,作为POC的一部分,用于从Azure迁移到AWS API管理。

我已经完成了所有工作,除了我无法找出YAML AWS扩展来设置HTTP请求的HTTP代理复选框。

以下示例YAML。我知道这不会设置该复选框(因为我已经测试了它并且它可以减去那个问题),但是在这个页面上

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration.html

我看不到设置此选项的扩展程序? AWS还没有这样做

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  PlayersAPI:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: RAH API
      Description: A demo API for testing
      Body:
        swagger: '2.0'
        info:
          title: test api
          description: test api
          version: 1.0.1
          contact:
            name: SH
            email: test@mailinator.com
        paths:
          "/heartbeat":
            get:
              description: Checks the API is working
              produces:
              - application/json
              responses:
                '200':
                  description: API Response information
              x-amazon-apigateway-integration:
                type: http
                responses:
                  default:
                    statusCode: '200'
                httpMethod: GET
                uri: https://api.example.com

1 个答案:

答案 0 :(得分:0)

这对我有用:

resources:
  Resources:
    ProxyResource:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId:
          Fn::GetAtt:
            - ApiGatewayRestApi # our default Rest API logical ID
            - RootResourceId
        PathPart: "{proxy+}" # the endpoint in your API that is set as proxy
        RestApiId:
          Ref: ApiGatewayRestApi
    ProxyMethod:
      Type: AWS::ApiGateway::Method
      Properties:
        ResourceId:
          Ref: ProxyResource
        RestApiId:
          Ref: ApiGatewayRestApi
        HttpMethod: GET # the method of your proxy. Is it GET or POST or ... ?
        MethodResponses:
          - StatusCode: 200
        Integration:
          IntegrationHttpMethod: GET
          Type: HTTP_PROXY
          Uri: http://bucket.mybucket.co.s3.eu-west-1.amazonaws.com/{proxy} # the URL you want to set a proxy to
          IntegrationResponses:
            - StatusCode: 200
        AuthorizationType: NONE