简体   繁体   中英

AWS SAM Template: Create proxy via AWS::Serverless::Api

I am looking for a way to define a simple AWS ApiGateway proxy via AWS SAM (AWS::Serverless::Api)

eg

foo.com/unitrans -> accesses a file in AWS S3 and return it's content.

在此处输入图片说明

Is there a way to do that?

@Alex Thank you for that post and it helped. Here is what I ended up doing.

    AMASApiGateway:
    Type: "AWS::ApiGateway::RestApi"
    Properties:
      Name: "amas-api"
      Description: "Aggie Mobile Api Service : API"

  AMASApiResource:
    Type: 'AWS::ApiGateway::Resource'
    Properties:
      ParentId: !GetAtt AMASApiGateway.RootResourceId
      RestApiId: !Ref AMASApiGateway
      PathPart: 'unitrans'

  AMASApiProxyMethod:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      HttpMethod: GET
      ResourceId: !Ref AMASApiResource
      RestApiId: !Ref AMASApiGateway
      AuthorizationType: NONE
      RequestParameters:
        method.request.path.proxy: true
      Integration:
        CacheKeyParameters:
          - 'method.request.path.proxy'
        RequestParameters:
          integration.request.path.proxy: 'method.request.path.proxy'
        IntegrationHttpMethod: GET
        Type: HTTP_PROXY
        Uri: !Sub '<S3 hosted JSON file URI>'
        PassthroughBehavior: WHEN_NO_MATCH
        IntegrationResponses:
          - StatusCode: 200

  AMASApiGatewayDeployment:
    Type: "AWS::ApiGateway::Deployment"
    DependsOn:
      - "AMASApiProxyMethod"
    Properties:
      RestApiId: !Ref AMASApiGateway
      StageName: !Ref Environment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM