ALIYUN::ApiGateway::PluginAttachment类型用于将插件绑定到API。
语法
{
"Type": "ALIYUN::ApiGateway::PluginAttachment",
"Properties": {
"StageName": String,
"PluginId": String,
"ApiId": String
}
}
属性
|
属性名称 |
类型 |
必须 |
允许更新 |
描述 |
约束 |
|
ApiId |
String |
是 |
否 |
API编号。 |
无 |
|
PluginId |
String |
是 |
否 |
插件ID。 |
无 |
|
StageName |
String |
是 |
否 |
操作API的环境。 |
取值:
|
返回值
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必须是发布状态才可满足,否则会出现绑定或解绑失败的情况。