Tag Editor(AWS Resource Groups and Tags)でサポートされていない Amazon API Gateway のリソース情報を取得する方法を教えてください

2021.12.07

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

この記事はアノテーション株式会社 AWS Technical Support Advent Calendar 2021のカレンダー | Advent Calendar 2021 - Qiita 7日目の記事です。

困っていた内容

Tag Editor(AWS Resource Groups and Tags)において、タグ付けしたAmazon API Gatewayの全てのリソース情報を取得しようと試みましたが、Amazon API GatewayについてはTag Editorのサポート対象外であるため、こちらの方法では取得できないことが分かりました。

Tag Editorのサポート対象外であるAmazon API Gatewayの全てのリソース情報を取得するために、他の方法があれば教えてください。

他にどんな方法があるの

以下のAWS CLIコマンドにより、API Gatewayの全てのリソース情報について取得することが可能です。

  • get-apis

  • get-rest-apis

API Gatewayを作成する際に、以下の4つのAPIタイプが選択できますが、取得したいAPIタイプに応じて、API Gatewayのリソース情報を取得する上記のAWS CLIコマンドを使い分けます。

  • HTTP API
  • WebSocket API
  • REST API
  • REST API(プライベート)

どう取得すればいいの?

以下、APIタイプ毎の取得する例を示します。

「HTTP API」と「WebSocket API」の取得例

「HTTP API」と「WebSocket API」におけるAPI Gatewayのリソース情報を取得するコマンド実行例を以下に示します。

  • コマンド実行例:「HTTP API」と「WebSocket API」のリソース情報の取得
$ aws apigatewayv2 get-apis
{
    "Items": [
        {
            "Name": "test-http-api",
            "Tags": {
                "api": "sample"
            },
            "ProtocolType": "HTTP",
            "RouteSelectionExpression": "$request.method $request.path",
            "ApiId": "8coeuk6dhh",
            "ApiEndpoint": "https://8coeuk6dhh.execute-api.ap-northeast-1.amazonaws.com",
            "ApiKeySelectionExpression": "$request.header.x-api-key",
            "CreatedDate": "2021-11-16T07:45:15Z",
            "DisableExecuteApiEndpoint": false
        },
        {
            "Name": "test-web-socket-api",
            "Tags": {},
            "ProtocolType": "WEBSOCKET",
            "RouteSelectionExpression": "$request.body.action",
            "ApiId": "c0eo8khqzj",
            "ApiEndpoint": "wss://c0eo8khqzj.execute-api.ap-northeast-1.amazonaws.com",
            "ApiKeySelectionExpression": "$request.header.x-api-key",
            "CreatedDate": "2021-11-16T07:46:14Z",
            "DisableExecuteApiEndpoint": false
        }
    ]
}

「REST API」と「REST API(プライベート)」の取得例

「REST API」と「REST API(プライベート)」におけるAPI Gatewayのリソース情報を取得するコマンド実行例を以下に示します。

  • コマンド実行例:「REST API」と「REST API(プライベート)」のリソース情報の取得
$ aws apigateway get-rest-apis
{
    "items": [
        {
            "apiKeySource": "HEADER",
            "name": "test-rest-api-2",
            "endpointConfiguration": {
                "types": [
                    "PRIVATE"
                ]
            },
            "createdDate": 1637050175,
            "disableExecuteApiEndpoint": false,
            "id": "8mlyh4cj5f"
        },
        {
            "apiKeySource": "HEADER",
            "name": "test-rest-api",
            "endpointConfiguration": {
                "types": [
                    "REGIONAL"
                ]
            },
            "createdDate": 1637048808,
            "disableExecuteApiEndpoint": false,
            "id": "j2cltoqad5"
        }
    ]
}

参考資料