すべてのプロダクト
Search
ドキュメントセンター

Resource Orchestration Service:ALIYUN::ApiGateway::PluginAttachment

最終更新日:Jan 24, 2026

ALIYUN::ApiGateway::PluginAttachment は、API にプラグインをバインドするために使用されます。

構文

{
  "Type": "ALIYUN::ApiGateway::PluginAttachment",
  "Properties": {
    "StageName": String,
    "PluginId": String,
    "ApiId": String
  }
}

プロパティ

プロパティ名

タイプ

必須

更新の許可

説明

制約

ApiId

String

はい

いいえ

API の ID。

なし。

PluginId

String

はい

いいえ

プラグインの ID。

なし。

StageName

String

はい

いいえ

API の操作環境。

有効な値:

  • RELEASE: リリース環境

  • PRE: プレリリース環境

  • TEST: テスト環境

戻り値

Fn::GetAtt

  • PluginId: プラグインの ID。

  • ApiId: API の ID。

シナリオ 1:既存の API へのプラグインのアタッチ

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ApiId:
    Description: プラグインをバインドする API の ID。
    Type: String
  PluginId:
    Description: バインドするプラグインの ID。
    Type: String
  StageName:
    AllowedValues:
    - RELEASE
    - PRE
    - TEST
    Description: "ランタイム環境の名前。有効な値:\nRELEASE:リリース環境を示します。\nPRE:プレリリース環境を示します。\nTEST:テスト環境を示します。"
    Type: String
Resources:
  PluginAttachment:
    Properties:
      ApiId:
        Ref: ApiId
      PluginId:
        Ref: PluginId
      StageName:
        Ref: StageName
    Type: ALIYUN::ApiGateway::PluginAttachment
Outputs:
  ApiId:
    Description: API ID。
    Value:
      Fn::GetAtt:
      - PluginAttachment
      - ApiId
  PluginId:
    Description: プラグイン ID。
    Value:
      Fn::GetAtt:
      - PluginAttachment
      - PluginId
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ApiId": {
      "Description": "プラグインをバインドする API の ID。",
      "Type": "String"
    },
    "PluginId": {
      "Description": "バインドするプラグインの ID。",
      "Type": "String"
    },
    "StageName": {
      "AllowedValues": [
        "RELEASE",
        "PRE",
        "TEST"
      ],
      "Description": "ランタイム環境の名前。有効な値:\nRELEASE:リリース環境を示します。\nPRE:プレリリース環境を示します。\nTEST:テスト環境を示します。",
      "Type": "String"
    }
  },
  "Resources": {
    "PluginAttachment": {
      "Properties": {
        "ApiId": {
          "Ref": "ApiId"
        },
        "PluginId": {
          "Ref": "PluginId"
        },
        "StageName": {
          "Ref": "StageName"
        }
      },
      "Type": "ALIYUN::ApiGateway::PluginAttachment"
    }
  },
  "Outputs": {
    "ApiId": {
      "Description": "API ID。",
      "Value": {
        "Fn::GetAtt": [
          "PluginAttachment",
          "ApiId"
        ]
      }
    },
    "PluginId": {
      "Description": "プラグイン ID。",
      "Value": {
        "Fn::GetAtt": [
          "PluginAttachment",
          "PluginId"
        ]
      }
    }
  }
}

シナリオ 2:新しい API とプラグインの作成とアタッチ

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  VpcId:
    Description: VPC の ID
    Type: String
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
  ECSInstanceId:
    Description: ECS インスタンスの ID。
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::InstanceId
  APIGroupId:
    Description: ApiGateway グループの ID。
    Type: String
  PluginData:
    Description: ApiGateway プラグインのデータ。
    Type: String
    Default: "type: ALLOW \t     # コントロールモード。有効な値:ALLOW はホワイトリストモード、REFUSE はブラックリストモードです。\nitems:\n  - blocks:          # IP アドレスブロック\n      - 78.11.12.2   # IP アドレス\n      - 61.3.9.0/24  # CIDR ブロック\n  - blocks:          # IP アドレスブロック\n      - 79.11.12.2   # IP アドレス"
Resources:
  ApiGatewayApi:
    Type: ALIYUN::ApiGateway::Api
    Properties:
      AuthType: APP
      ServiceConfig:
        ServiceHttpMethod: GET
        ServiceProtocol: HTTP
        ServiceVpcEnable: 'TRUE'
        VpcConfig:
          InstanceId:
            Ref: ECSInstanceId
          VpcId:
            Ref: VpcId
          Port: 80
        ServicePath: /backend
      RequestConfig:
        RequestHttpMethod: GET
        RequestPath: /path/to/resource
      Visibility: PUBLIC
      ApiName: api_2026-01-12-11-38-54
      GroupId:
        Ref: APIGroupId
  ApiGatewayPlugin:
    Type: ALIYUN::ApiGateway::Plugin
    Properties:
      PluginName: TestPlugin
      PluginData:
        Ref: PluginData
      PluginType: trafficControl
  ApiGatewayDeployment:
    Type: ALIYUN::ApiGateway::Deployment
    Properties:
      ApiId:
        Ref: ApiGatewayApi
      GroupId:
        Ref: APIGroupId
      StageName: RELEASE
  ApiGatewayPluginAttachment:
    Type: ALIYUN::ApiGateway::PluginAttachment
    DependsOn:
      - ApiGatewayDeployment
    Properties:
      PluginId:
        Ref: ApiGatewayPlugin
      ApiId:
        Ref: ApiGatewayApi
      StageName: RELEASE
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "VpcId": {
      "Description": "VPC の ID",
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VPC::VPCId"
    },
    "ECSInstanceId": {
      "Description": "ECS インスタンスの ID。",
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceId"
    },
    "APIGroupId": {
      "Description": "ApiGateway グループの ID。",
      "Type": "String"
    },
    "PluginData": {
      "Description": "ApiGateway プラグインのデータ。",
      "Type": "String",
      "Default": "type: ALLOW \t     # コントロールモード。有効な値:ALLOW はホワイトリストモード、REFUSE はブラックリストモードです。\nitems:\n  - blocks:          # IP アドレスブロック\n      - 78.11.12.2   # IP アドレス\n      - 61.3.9.0/24  # CIDR ブロック\n  - blocks:          # IP アドレスブロック\n      - 79.11.12.2   # IP アドレス"
    }
  },
  "Resources": {
    "ApiGatewayApi": {
      "Type": "ALIYUN::ApiGateway::Api",
      "Properties": {
        "AuthType": "APP",
        "ServiceConfig": {
          "ServiceHttpMethod": "GET",
          "ServiceProtocol": "HTTP",
          "ServiceVpcEnable": "TRUE",
          "VpcConfig": {
            "InstanceId": {
              "Ref": "ECSInstanceId"
            },
            "VpcId": {
              "Ref": "VpcId"
            },
            "Port": 80
          },
          "ServicePath": "/backend"
        },
        "RequestConfig": {
          "RequestHttpMethod": "GET",
          "RequestPath": "/path/to/resource"
        },
        "Visibility": "PUBLIC",
        "ApiName": "api_2026-01-12-11-38-54",
        "GroupId": {
          "Ref": "APIGroupId"
        }
      }
    },
    "ApiGatewayPlugin": {
      "Type": "ALIYUN::ApiGateway::Plugin",
      "Properties": {
        "PluginName": "TestPlugin",
        "PluginData": {
          "Ref": "PluginData"
        },
        "PluginType": "trafficControl"
      }
    },
    "ApiGatewayDeployment": {
      "Type": "ALIYUN::ApiGateway::Deployment",
      "Properties": {
        "ApiId": {
          "Ref": "ApiGatewayApi"
        },
        "GroupId": {
          "Ref": "APIGroupId"
        },
        "StageName": "RELEASE"
      }
    },
    "ApiGatewayPluginAttachment": {
      "Type": "ALIYUN::ApiGateway::PluginAttachment",
      "DependsOn": [
        "ApiGatewayDeployment"
      ],
      "Properties": {
        "PluginId": {
          "Ref": "ApiGatewayPlugin"
        },
        "ApiId": {
          "Ref": "ApiGatewayApi"
        },
        "StageName": "RELEASE"
      }
    }
  }
}
重要

プラグインをアタッチまたはデタッチする場合、API は公開状態である必要があります。そうでない場合、操作は失敗します。