AWS SAM模板:通过AWS :: Serverless :: Api

时间:2020-01-09 00:20:24

标签: amazon-web-services aws-api-gateway aws-sam

我正在寻找一种通过AWS SAM(AWS :: Serverless :: Api)定义简单的AWS ApiGateway代理的方法

例如

foo.com/unitrans->访问AWS S3中的文件并返回其内容。

enter image description here

有办法吗?

1 个答案:

答案 0 :(得分:0)

@Alex谢谢您的帖子,它对您有所帮助。这就是我最后要做的。

    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