Reputation: 972
I have a Cloudformation template which has API Gateway defined with title Employee Management API
. I like to reference this title when I define a Cloudwatch Dashboard for the API Gateway. Right now I hard coded the title of the API Gateway into the dashboard metrics. Instead if I am able to Ref the title property of the API Gateway it is better.
Pasted below are parts of the Cloudformation Template which defines the API Gateway and Dashboard.
Cloudformation Template for API Gateway:
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: "[email protected]"
basePath: "/v1"
tags:
- name: "employee"
description: "Operations related to a employee"
schemes:
- "https"
paths:
/brands:
.
.
.
Cloudformation Template for Dashboard for API Gateway
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"
}
}
]
}'
Upvotes: 2
Views: 2138
Reputation: 1911
As of October 2018 this is not supported. Return values for AWS::ApiGateway::RestApi do not include ApiName. Also the Cloudwatch metrics for ApiGateway only support filtering on ApiName. The workaround we are using is to reference the same stack parameter in both places. So in your case you could do something like
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} ]
Upvotes: 2
Reputation: 7344
I believe you can reference a Stack Output
across multiple stacks like so:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html
Upvotes: -1