我有一个云表单模板,其中定义了标题为Employee Management API的API Gateway。当我为API网关定义Cloudwatch Dashboard时,我喜欢引用此标题。现在,我将API Gateway的标题硬编码到仪表板指标中。相反,如果我能够引用API Gateway的title属性,那就更好了。
下面粘贴的是Cloudformation模板的一部分,它定义了API网关和仪表板。
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"
}
}
]
}'发布于 2018-10-18 05:51:33
从2018年10月起,不支持此功能。Return values for AWS::ApiGateway::RestApi不包括ApiName。此外,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} ]发布于 2017-12-22 10:03:29
我相信您可以跨多个堆栈引用堆栈Output,如下所示:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html
https://stackoverflow.com/questions/47895883
复制相似问题