您可以通过在每个路由的模板中定义CloudWatch Enpoint属性来为每个API网关路由添加唯一的CloudWatch Endpoint。以下是一个示例代码片段,其中每个路由都有不同的CloudWatch Endpoint:
{
"swagger": "2.0",
"info": {
"title": "API Gateway Example",
"version": "1.0"
},
"paths": {
"/route1": {
"x-amazon-apigateway-any-method": {
"parameters": [
{
"name": "CloudWatchEndpoint",
"in": "header",
"required": true,
"type": "string",
"default": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/api-gateway/my-api"
}
],
"x-amazon-apigateway-integration": {
"type": "http",
"httpMethod": "POST",
"uri": "https://example.com",
"passthroughBehavior": "when_no_templates",
"requestParameters": {
"integration.request.header.CloudWatchEndpoint": "method.request.header.CloudWatchEndpoint"
}
}
}
},
"/route2": {
"x-amazon-apigateway-any-method": {
"parameters": [
{
"name": "CloudWatchEndpoint",
"in": "header",
"required": true,
"type": "string",
"default": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/api-gateway/my-api-route2"
}
],
"x-amazon-apigateway-integration": {
"type": "http",
"httpMethod": "POST",
"uri": "https://example.com",
"passthroughBehavior": "when_no_templates",
"requestParameters": {
"integration.request.header.CloudWatchEndpoint": "method.request.header.CloudWatchEndpoint"
}
}
}
}
}
}
在此示例中,每个路由都在parameters部分定义了一个名为CloudWatchEndpoint的属性,并在x