LoginSignup
3
5

More than 5 years have passed since last update.

SAM で API Gateway の Base Path Mapping を設定する

Last updated at Posted at 2018-02-17

この記事は、AWS Serverless Application Model (AWS SAM) で API Gateway の Base Path Mapping を設定しようとした際の記録です。

AWS Serverless Application Model (AWS SAM) とは

  • AWS がサーバーレスアプリケーションを構築するためのフレームワーク
  • Lambda, API Gateway, DynamoDB などのリソースを手軽に管理できる
  • ベースは AWS CloudFormation

参考

SAM で API Gateway の Base Path Mapping を設定する(2018/05/18追記)

  • SAM の AWS::Serverless::Api では Base Path Mapping の設定ができない

  • AWS::Serverless::Api と一緒に AWS::ApiGateway::BasePathMapping のリソースを作成する

    • AWS::ApiGateway::BasePathMapping の Stage に指定する値は、AWS::Serverless::Api から取得できないため、以下の値を指定する
    • AWS::Serverless::Api のリソース名 + AWS::Serverless::Api の StageName + "Stage"
  • AWS::ApiGateway::BasePathMapping の Stage には以下の値を指定する

    • !Ref MyApi.Stage
    • 2018/03/13 にリリースされた SAM v1.4.0 にて API の Stage への参照が使えるようになりました
template.yml

  SampleApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionUri: /path_to_swagger/swagger.yml

  SampleApiBasePathMapping:
    Type: AWS::ApiGateway::BasePathMapping
    Properties:
      DomainName: sample.api.example.com
      RestApiId: !Ref SampleApi
      BasePath: v1
      Stage: !Ref SampleApi.Stage

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5