全部產品
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編號。

PluginId

String

外掛程式ID。

StageName

String

操作API的環境。

取值:

  • RELEASE:發布環境。

  • PRE:預發布環境。

  • TEST:測試環境。

傳回值

Fn::GetAtt

  • PluginId:外掛程式ID。

  • ApiId:API編號。

樣本

情境 1 :使用已有的API與外掛程式建立綁定關係

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ApiId:
    Description: The ID of the API to which you want to bind the plug-in.
    Type: String
  PluginId:
    Description: The ID of the plugin that you want to bind.
    Type: String
  StageName:
    AllowedValues:
    - RELEASE
    - PRE
    - TEST
    Description: "The name of the runtime environment. Valid values: \nRELEASE: indicates\
      \ the release environment.\nPRE: indicates the pre-release environment.\nTEST:\
      \ indicates the test environment."
    Type: String
Resources:
  PluginAttachment:
    Properties:
      ApiId:
        Ref: ApiId
      PluginId:
        Ref: PluginId
      StageName:
        Ref: StageName
    Type: ALIYUN::ApiGateway::PluginAttachment
Outputs:
  ApiId:
    Description: The api id.
    Value:
      Fn::GetAtt:
      - PluginAttachment
      - ApiId
  PluginId:
    Description: The plugin id.
    Value:
      Fn::GetAtt:
      - PluginAttachment
      - PluginId
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ApiId": {
      "Description": "The ID of the API to which you want to bind the plug-in.",
      "Type": "String"
    },
    "PluginId": {
      "Description": "The ID of the plugin that you want to bind.",
      "Type": "String"
    },
    "StageName": {
      "AllowedValues": [
        "RELEASE",
        "PRE",
        "TEST"
      ],
      "Description": "The name of the runtime environment. Valid values: \nRELEASE: indicates the release environment.\nPRE: indicates the pre-release environment.\nTEST: indicates the test environment.",
      "Type": "String"
    }
  },
  "Resources": {
    "PluginAttachment": {
      "Properties": {
        "ApiId": {
          "Ref": "ApiId"
        },
        "PluginId": {
          "Ref": "PluginId"
        },
        "StageName": {
          "Ref": "StageName"
        }
      },
      "Type": "ALIYUN::ApiGateway::PluginAttachment"
    }
  },
  "Outputs": {
    "ApiId": {
      "Description": "The api id.",
      "Value": {
        "Fn::GetAtt": [
          "PluginAttachment",
          "ApiId"
        ]
      }
    },
    "PluginId": {
      "Description": "The plugin id.",
      "Value": {
        "Fn::GetAtt": [
          "PluginAttachment",
          "PluginId"
        ]
      }
    }
  }
}

情境 2 :建立API和外掛程式並建立綁定關係

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  VpcId:
    Description: The ID of the VPC
    Type: String
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
  ECSInstanceId:
    Description: The ID of the ECS Instance.
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::InstanceId
  APIGroupId:
    Description: The ID of the ApiGateway GroupId.
    Type: String
  PluginData:
    Description: The ApiGateway Plugin Data.
    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": "The ID of the VPC",
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VPC::VPCId"
    },
    "ECSInstanceId": {
      "Description": "The ID of the ECS Instance.",
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceId"
    },
    "APIGroupId": {
      "Description": "The ID of the ApiGateway GroupId.",
      "Type": "String"
    },
    "PluginData": {
      "Description": "The ApiGateway Plugin Data.",
      "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上的外掛程式時需要保證Api必須是發布狀態才可滿足,否則會出現綁定或解除綁定失敗的情況。