3

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

e.g.

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

enter image description here

Is there a way to do that?

tamsler
  • 1,275
  • 1
  • 18
  • 26

1 Answers1

1

@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
tamsler
  • 1,275
  • 1
  • 18
  • 26