LoginSignup
23
27

More than 5 years have passed since last update.

【AWS】【API Gateway】SwaggerでREST APIを一元管理

Last updated at Posted at 2015-11-10

AWS API Gateway上のAPIをSwaggerファイルから作成・更新してみます。

前提

準備

AWS Labsが提供する以下のツールを使います。

  1. リポジトリのclone
git clone https://github.com/awslabs/aws-apigateway-importer.git
cd aws-apigateway-importer
  1. ビルド
mvn assembly:assembly

使い方

APIの新規作成

SwaggerのスキーマファイルからAPI Gateway上でAPIを新規に作成します。

  1. 実行

    ./aws-api-import.sh --create [Swaggerのスキーマファイル]
    

    ※ Windowsの場合は./aws-api-import.cmdを使います。

  2. 実行結果

    リソース

    resource.png

    モデル

    models.png

APIの更新

Swaggerのスキーマファイルを元にAPI Gateway上のAPIを更新します。

  1. API IDの取得

    aws apigateway get-rest-apis
    

    更新したいAPIのidの値を取得します。

    例:

    {
        "items": [
         {
             "description": "Move your app forward with the Uber API",
             "createdDate": xxxxxxxxxx,
             "id": "xxxxxxxxxx",
             "name": "Uber API"
         },
         {
             "description": "Flashcard API",
             "createdDate": xxxxxxxxxx,
             "id": "xxxxxxxxxx",
             "name": "Flashcard API"
         },
    
        ]
    }
    
  2. 実行

    先ほど取得したIDとSwaggerのスキーマファイルを元にAPIを更新します。

    ./aws-api-import.sh --update [API ID] [Swaggerのスキーマファイル]
    

    ※デプロイしていない場合

その他

Swaggerではvendor extensionによってベンダが仕様を拡張できるようになっています。

AWS API Gatewayでは現在x-amazon-apigateway-authx-amazon-apigateway-integrationという項目が用意されていて、認証方法やバックエンドとの接続を設定できるようになっています。

23
27
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
23
27