AWS Cloudformation Cloudwatch 仪表板:参考 ApiGateway 标题
AWS Cloudformation Cloudwatch Dashboard : Ref ApiGateway Title
我有一个 Cloudformation 模板,其中 API 网关定义为标题 Employee Management API
。当我为 API 网关定义 Cloudwatch 仪表板时,我喜欢引用这个标题。现在,我将 API 网关的标题硬编码到仪表板指标中。相反,如果我能够引用 API 网关的标题 属性,那就更好了。
下面粘贴的是定义 API 网关和仪表板的 Cloudformation 模板的一部分。
API 网关的 Cloudformation 模板:
EmployeeApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionBody:
swagger: "2.0"
info:
description: "This API allows clients to query and manage employees"
version: "1.0.0"
title: "Employee Management API"
contact:
email: "me@me.com"
basePath: "/v1"
tags:
- name: "employee"
description: "Operations related to a employee"
schemes:
- "https"
paths:
/brands:
.
.
.
API 网关仪表板的 Cloudformation 模板
EmployeeAPIDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: "EmployeeAPIDashboard"
DashboardBody:
Fn::Sub: '{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 6,
"height": 6,
"properties": {
"view": "timeSeries",
"stacked": false,
"metrics": [
[ "AWS/ApiGateway", "IntegrationLatency", "ApiName", "Employee Management API", "Stage", "Prod", { "period": 86400, "yAxis": "right", "stat": "Sum" } ],
[ ".", "Count", ".", ".", ".", ".", { "period": 86400, "stat": "Sum"} ],
[ ".", "Latency", ".", ".", ".", ".", { "period": 86400, "yAxis": "right", "stat": "Sum"} ],
[ ".", "5XXError", ".", ".", ".", ".", { "period": 86400, "stat": "Sum", "color": "#FF0000" } ],
[ ".", "4XXError", ".", ".", ".", ".", { "period": 86400, "stat": "Sum", "color": "#FFA500" } ]
],
"region": "us-west-2",
"period": 300,
"title": "API Gateway"
}
}
]
}'
我相信您可以像这样跨多个堆栈引用堆栈 Output
:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html
截至 2018 年 10 月,此功能不受支持。 Return values for AWS::ApiGateway::RestApi do not include ApiName. Also the Cloudwatch metrics for ApiGateway 仅支持对 ApiName 进行过滤。我们使用的解决方法是在两个地方引用相同的堆栈参数。所以在你的情况下你可以做类似
的事情
Parameters:
MyApiName:
Type: String
Default: "Employee Management API"
Resources:
EmployeeApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
DefinitionBody:
info:
title: !Ref MyApiName
EmployeeAPIDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardBody:
Fn::Sub: '{
"widgets": [
{
"properties": {
"metrics": [
[ "ApiName", ${MyApiName} ]
我有一个 Cloudformation 模板,其中 API 网关定义为标题 Employee Management API
。当我为 API 网关定义 Cloudwatch 仪表板时,我喜欢引用这个标题。现在,我将 API 网关的标题硬编码到仪表板指标中。相反,如果我能够引用 API 网关的标题 属性,那就更好了。
下面粘贴的是定义 API 网关和仪表板的 Cloudformation 模板的一部分。
API 网关的 Cloudformation 模板:
EmployeeApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionBody:
swagger: "2.0"
info:
description: "This API allows clients to query and manage employees"
version: "1.0.0"
title: "Employee Management API"
contact:
email: "me@me.com"
basePath: "/v1"
tags:
- name: "employee"
description: "Operations related to a employee"
schemes:
- "https"
paths:
/brands:
.
.
.
API 网关仪表板的 Cloudformation 模板
EmployeeAPIDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: "EmployeeAPIDashboard"
DashboardBody:
Fn::Sub: '{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 6,
"height": 6,
"properties": {
"view": "timeSeries",
"stacked": false,
"metrics": [
[ "AWS/ApiGateway", "IntegrationLatency", "ApiName", "Employee Management API", "Stage", "Prod", { "period": 86400, "yAxis": "right", "stat": "Sum" } ],
[ ".", "Count", ".", ".", ".", ".", { "period": 86400, "stat": "Sum"} ],
[ ".", "Latency", ".", ".", ".", ".", { "period": 86400, "yAxis": "right", "stat": "Sum"} ],
[ ".", "5XXError", ".", ".", ".", ".", { "period": 86400, "stat": "Sum", "color": "#FF0000" } ],
[ ".", "4XXError", ".", ".", ".", ".", { "period": 86400, "stat": "Sum", "color": "#FFA500" } ]
],
"region": "us-west-2",
"period": 300,
"title": "API Gateway"
}
}
]
}'
我相信您可以像这样跨多个堆栈引用堆栈 Output
:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html
截至 2018 年 10 月,此功能不受支持。 Return values for AWS::ApiGateway::RestApi do not include ApiName. Also the Cloudwatch metrics for ApiGateway 仅支持对 ApiName 进行过滤。我们使用的解决方法是在两个地方引用相同的堆栈参数。所以在你的情况下你可以做类似
的事情Parameters:
MyApiName:
Type: String
Default: "Employee Management API"
Resources:
EmployeeApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
DefinitionBody:
info:
title: !Ref MyApiName
EmployeeAPIDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardBody:
Fn::Sub: '{
"widgets": [
{
"properties": {
"metrics": [
[ "ApiName", ${MyApiName} ]