Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

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?

like image 480
tamsler Avatar asked Apr 20 '26 06:04

tamsler


1 Answers

@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
like image 73
tamsler Avatar answered Apr 22 '26 22:04

tamsler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!