Hi there,
I am using serverless.yml
to create both an API Gateway v2 (HTTP API) and a CloudWatch Dashboard to monitor it.
Unfortunately, CloudWatch Dashboard does not support monitoring an API Gateway v2 by API NAME. The only way to do it is using ApiId. The problem is that sometimes that ID changes. Is there any way I can dynamically retrieve the ID of the HTTP API I am deploying and inject it into the CloudFormation template of the CloudWatch dashboard?
Hopefully my code below makes some sense:
provider:
httpApi:
metrics: true
resources:
Resources:
MyDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: MyDashboard
DashboardBody: '
{
"widgets": [
{
"type": "metric",
"properties": {
"metrics": [
[
"AWS/ApiGateway",
"4xx",
"Resource",
"/{proxy+}",
"Stage",
"$default",
"Method",
"ANY",
"ApiId",
"f8d7a6fd8", ============> I want this to be a variable such as ${self:provider.myApiId}
{
"yAxis": "left"
}
]
],
"view": "bar",
"stacked": false,
"region": "us-west-2",
"period": 300,
"stat": "Sum",
"setPeriodToTimeRange": true
}
}
]
}
'