Cloudwatch: Creating cloudwatch alarms on existing metrics
See original GitHub issueHey guys,
I don’t know if this is a feature request or a gap in the current documentation but I was wondering if it would be possible to create cloudwatch alarms on existing metrics. For example, when creating an ELB with CDK specific metrics come out of the box like: Response times. It would be great to be able to reference an already created cloudwatch metric like:
const myExistingMetric = fn.metricErrors({
namespace: "SomeNameSpace",
metricName: "someMetricName"
});
new Alarm(this, 'CustomeAlarm', {
metric: myExistingMetric,
EvaluationPeriods: 2,
threshold: 1,
Statistic: 'Average',
Period: 300, // five minutes
});
I don’t exactly know great error handling mechanisms when those metrics don’t exist, but perhaps it would even expose what metrics are available out of the box.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Set a CloudWatch alarm - AWS Documentation
Once you have a metric, either an existing one or one you defined, you can create an alarm. In this example, the alarm...
Read more >typescript - Creating a Cloudwatch alarm on an existing ...
I need to set alarms for these already existing metrics in CDK. I cannot find how you can import pre-existing CloudWatch metrics in...
Read more >Tutorial: Setting up AWS CloudWatch Alarms - Coralogix
You can create metric filters using data logged by AWS services such as Lambda. Once Lambda logs are in CloudWatch, you can create...
Read more >Creating alarms in Amazon CloudWatch — Boto3 Docs 1.26 ...
An alarm watches a single metric over a time period you specify, and performs one or more actions based on the value of...
Read more >CloudWatch Metric Math: Tutorial With Examples - OpsRamp
CloudWatch is a great tool to visualize the metrics as-is, but if you want to go to the next level of metrics aggregation,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there any way to import existing metrics so that they can be used when creating alarms? I was thinking of something similar to
Vpc.fromLookup
.As I understand it, the approach outlined in Doug’s link only works if you know the correct values needed to construct the metric (the namespace, metric name, and dimensions). We have a use case where a dimension of the metric is the ID of the container posting it, and so we cannot predict the dimensions from the CDK code.
It would be ideal if we could do something like:
In the absence of such a method to import existing metrics, the best approach I can think of is to use
ListMetrics
from the CloudWatch SDK to get the metrics from the account. However, the SDK is async, so the call toListMetrics
(and the subsequent creation of alarms on these metrics) can’t be done in a constructor, as a constructor can’t be async. Instead, it has to be done in some sort of initalizer method. This feels like it breaks the normal CDK pattern of creating all child resources in the constructor.Overall, my questions are:
initialize
method to our CDK classes?We ended up deciding to create alarms with the CloudWatch SDK when the container is created rather than trying to keep these alarms in our CDK code. Answers to the questions above would still be interesting and potentially valuable others who end up on this thread though.