全部产品
Search
文档中心

Resource Orchestration Service:ALIYUN::ApiGateway::PluginAttachment

更新时间:Jan 24, 2026

ALIYUN::ApiGateway::PluginAttachment digunakan untuk mengikat Plugin ke API.

Sintaksis

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

Properti

Property Name

Tipe

Diperlukan

Allow Updates

Deskripsi

Kendala

ApiId

String

Ya

Tidak

ID dari API.

Tidak ada.

PluginId

String

Ya

Tidak

ID dari Plugin.

Tidak ada.

StageName

String

Ya

Tidak

Lingkungan operasi API.

Nilai yang valid:

  • RELEASE: lingkungan rilis

  • PRE: lingkungan pra-rilis

  • TEST: Lingkungan pengujian

Nilai Pengembalian

Fn::GetAtt

  • PluginId: ID dari Plugin.

  • ApiId: ID dari API.

Contoh

Skenario 1: Menyambungkan plug-in ke API yang sudah ada

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"
        ]
      }
    }
  }
}

Skenario 2: Membuat API dan plug-in baru lalu menyambungkannya

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     # The control mode. Valid values: ALLOW for whitelist mode and REFUSE for blacklist mode.\nitems:\n  - blocks:          # IP address block\n      - 78.11.12.2   # IP address\n      - 61.3.9.0/24  # CIDR block\n  - blocks:          # IP address block\n      - 79.11.12.2   # IP address"
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     # The control mode. Valid values: ALLOW for whitelist mode and REFUSE for blacklist mode.\nitems:\n  - blocks:          # IP address block\n      - 78.11.12.2   # IP address\n      - 61.3.9.0/24  # CIDR block\n  - blocks:          # IP address block\n      - 79.11.12.2   # IP address"
    }
  },
  "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"
      }
    }
  }
}
Penting

Saat menyambungkan atau melepas plug-in, API harus berada dalam status published. Jika tidak, operasi akan gagal.