awsdocs / aws-cdk-guide

User guide for the AWS Cloud Development Kit (CDK).
Other
335 stars 222 forks source link

Improve CloudWatch Alarm example #166

Open ghost opened 4 years ago

ghost commented 4 years ago

Received a customer report that it doesn't work

cmckni3 commented 4 years ago

is it this page? https://docs.aws.amazon.com/cdk/latest/guide/how_to_set_cw_alarm.html

I would combine the metric and alarm code in the first example

const metric = new cloudwatch.Metric({
  namespace: 'MyNamespace',
  metricName: 'MyMetric',
  dimensions: { MyDimension: 'MyDimensionValue' }
});

const alarm = new cloudwatch.Alarm(this, 'Alarm', {
  metric,
  threshold: 100,
  evaluationPeriods: 3,
  datapointsToAlarm: 2,
});
cmckni3 commented 4 years ago

I would also give a real example or state the example shows how to use it with a custom metric named "MyMetric" in the namespace "MyNamespace". I don't remember dimensions of the top of my head but they were somewhat restrictive in what CloudWatch supported.