The most powerful feature of CloudWatch are alarms. Alarms are triggers that are executed in response to CloudWatch events. For example, you can set up an alarm that is triggered when TotalErrorRate metric for our CloudFront distribution exceeds some threshold.
To create an alarm easily, you can click the Create alarm button (ring icon) on the Graphed metrics tab. Please now find the CloudFront's TotalErrorRate metric, select it and change to the Graphed metrics tab, and click to the Create alarm button. You will see the following screen:
![](assets/62902b0e-ff3c-416d-ab91-f089ce7e1cf8.png)
Here, you should fill Name field, and in the Actions section you should select the ServerlessBookDown topic. After that, you need to click the + Notification button, and this time you should select State is OK for the Whenever this alarm value and the same SNS topic. The tricky part is to determine the threshold. For this example, we picked is >= 5 for 1 consecutive period(s). This means whenever the error rate exceeds 5% for 5 minutes, the alarm will be triggered. You can play with these values according to your needs.
Now create the alarm and revert the change we did to the API Gateway endpoint, so put again authorization. After 5 minutes, as our health checkers will start to get error responses, you will observe this on the graph, and also the alarm will be triggered, so you will get an SMS.
You should have realized what a powerful feature this is. As you know, you can trigger almost anything with SNS, and CloudWatch alarms are also triggering SNS topics. This means that the sky is the limit for any orchestration of cloud events. For example, you can write a Lambda function that sends Slack messages to your team, and this function can be invoked when endless number of events happen in your application. Moreover, you do not need high integration efforts to have such a great monitoring solution.
One small thing left about alarms: our health check did not send us any message when it became healthy again. It was because for that alarm, the State is OK event was not configured by default. Now you can find that alarm, add this notification rule, and you will see that you will get notifications for downtime and when your application comes back online.