我有一个Cloudformation模板,其API网关定义为标题Employee Management API
。我在为API网关定义Cloudwatch仪表板时想引用此标题。现在,我将API网关的标题硬编码到仪表板指标中。相反,如果我能够参考API网关的标题属性,那就更好了。
下面粘贴的是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"
}
}
]
}'
答案 0 :(得分:1)
自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} ]
答案 1 :(得分:-1)
我相信你可以在多个堆栈中引用堆栈Output
,如下所示:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html