【发布时间】:2018-10-18 05:51:32
【问题描述】:
我有一个 Cloudformation 模板,其中定义了 API 网关,标题为 Employee Management API。当我为 API Gateway 定义 Cloudwatch 仪表板时,我喜欢引用这个标题。现在,我将 API Gateway 的标题硬编码到仪表板指标中。相反,如果我能够引用 API 网关的 title 属性,那就更好了。
下面粘贴的是定义 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"
}
}
]
}'
【问题讨论】:
标签: yaml aws-api-gateway amazon-cloudformation amazon-cloudwatch