

# Monitoring an Amplify application with Amazon CloudWatch
<a name="monitoring-with-cloudwatch"></a>

AWS Amplify is integrated with Amazon CloudWatch, enabling you to monitor metrics for your Amplify applications in near real-time, and create alarms that send notifications when a metric exceeds a threshold you set. For more information about how the CloudWatch service works, see the [Amazon CloudWatch User Guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html).

## Supported CloudWatch metrics
<a name="metrics"></a>

Amplify supports seven CloudWatch metrics in the `AWS/AmplifyHosting` namespace for monitoring traffic, errors, data transfer, latency, and request tokens for your apps. These metrics are aggregated at one minute intervals. CloudWatch monitoring metrics are free of charge and don't count against the [CloudWatch service quotas](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_limits.html).

The following table describes each supported metric and lists the most relevant statistics. Not all available statistics are applicable for every metric.


| Metric | Description | 
| --- | --- | 
|  Requests  |  The total number of viewer requests received by your app. The most relevant statistic is `Sum`. Use the `Sum` statistic to get the total number of requests.  | 
|  BytesDownloaded  |  The total amount of data transferred out of your app (downloaded) in bytes by viewers for `GET`, `HEAD`, and `OPTIONS` requests.  The most relevant statistic is `Sum`.  | 
|  BytesUploaded  |  The total amount of data transferred into your app (uploaded) in bytes for any request, including headers. Amplify doesn't charge you for data uploaded in your applications. The most relevant statistic is `Sum`.  | 
|  4xxErrors  |  The number of requests that returned an error in the HTTP status code 400-499 range. The most relevant statistic is `Sum`. Use the `Sum` statistic to get the total occurrences of these errors.  | 
|  5xxErrors  |  The number of requests that returned an error in the HTTP status code 500-599 range. The most relevant statistic is `Sum`. Use the `Sum` statistic to get the total occurrences of these errors.  | 
|  Latency  |  The time to first byte in seconds. This is the total time between when Amplify Hosting receives a request and when it returns a response to the network. This doesn't include the network latency encountered for a response to reach the viewer's device. The most relevant statistics are `Average`, `Maximum`, `Minimum`, `p10`, `p50`, `p90`, `p95`, and `p100`. Use the `Average` statistic to evaluate expected latencies.  | 
|  TokensConsumed  |  The request tokens consumed by your app.  The `Sum` statistic represents total request token consumption. You can compare this statistic to your current `Request tokens per second` service quota to determine whether you need to request a quota increase to avoid potential throttling during a future high traffic event. The `Average` statistic represents request token consumption across normal and peak times. Higher token consumption typically leads to longer time to first byte (TTFB). Therefore, you can use this statistic when evaluating your application's latency. If your latency is poor, you can improve your downstream APIs to reduce your token consumption and avoid the throttling that can occur when token consumption exceeds your application's `Request tokens per second` service quota. For more information about the `Request tokens per second` service quota, see [Amplify Hosting service quotas](quotas-chapter.md).  | 

Amplify provides the following CloudWatch metric dimensions.


| Dimension | Description | 
| --- | --- | 
|  App  |  Metric data is provided by app.  | 
|  AWS account  |  Metric data is provided across all apps in the AWS account.  | 

## Accessing CloudWatch metrics
<a name="access-cloudwatch-metrics"></a>

You can access CloudWatch metrics directly from the Amplify console using the following procedure.

**Note**  
You can also access CloudWatch metrics in the AWS Management Console at [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/). 

**To access metrics in the Amplify console**

1. Sign in to the AWS Management Console and open the [Amplify console](https://console.aws.amazon.com/amplify/).

1. Choose the app that you want to view metrics for.

1. In the navigation pane, choose **Monitoring**, then choose **Metrics**.

## Creating CloudWatch alarms
<a name="alarms"></a>

You can create CloudWatch alarms in the Amplify console that send notifications when specific criteria are met. An alarm watches a single CloudWatch metric and sends an Amazon Simple Notification Service notification when the metric breaches the threshold for a specified number of evaluation periods.

You can create more advanced alarms that use metric math expressions in the CloudWatch console or using the CloudWatch APIs. For example, you can create an alarm that notifies you when the percentage of 4xxErrors exceeds 15% for three consecutive periods. For more information, see [Creating a CloudWatch Alarm Based on a Metric Math Expression](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Create-alarm-on-metric-math-expression.html) in the *Amazon CloudWatch User Guide*. 

Standard CloudWatch pricing applies to alarms. For more information, see [Amazon CloudWatch pricing](https://aws.amazon.com/cloudwatch/pricing/).

Use the following procedure to create an alarm in the Amplify console.

**To create a CloudWatch alarm for an Amplify metric**

1. Sign in to the AWS Management Console and open the [Amplify console](https://console.aws.amazon.com/amplify/).

1. Choose the app that you want to set an alarm on.

1. In the navigation pane, choose **Monitoring**, then choose **Alarms**.

1. On the **Alarms** page, choose **Create alarm**.

1. In the **Create alarm** window, configure your alarm as follows:

   1. For **Metric**, choose the name of the metric to monitor from the list. 

   1. For **Name of alarm**, enter a meaningful name for the alarm. For example, if you are monitoring *Requests*, you could name the alarm **HighTraffic**. The name must contain only ASCII characters.

   1. For **Set up notifications**, do one of the following:
      + 

        1. Choose **New** to set up a new Amazon SNS topic.

        1. For **Email address**, enter the email address for the recipient of the notifications.

        1. Choose **Add new email address** to add additional recipients.
      + 

        1. Choose **Existing** to reuse an Amazon SNS topic.

        1. For **SNS topic**, select the name of an existing Amazon SNS topic from the list.

   1. For **Whenever the *Statistic* of *Metric***, set the conditions for your alarm as follows:

      1. Specify whether the metric must be greater than, less than, or equal to the threshold value.

      1. Specify the threshold value.

      1. Specify the number of consecutive evaluation periods that must be in the alarm state to invoke the alarm.

      1. Specify the length of time of the evaluation period.

   1. Choose **Confirm**.

**Note**  
Each Amazon SNS recipient that you specify receives a confirmation email from AWS Notifications. The email contains a link that the recipient must follow to confirm their subscription and receive notifications.

## Accessing CloudWatch Logs for SSR apps
<a name="ssr-logs"></a>

Amplify sends information about your SSR runtime to Amazon CloudWatch Logs in your AWS account. When you deploy an SSR app to Amplify Hosting compute, the app requires an IAM service role that Amplify assumes when calling other services on your behalf. You can either allow Amplify Hosting compute to automatically create a service role for you or you can specify a role that you have created.

If you choose to allow Amplify to create an IAM role for you, the role will already have the permissions to create CloudWatch Logs. If you create your own IAM role, you will need to add the following permissions to your policy to allow Amplify to access Amazon CloudWatch Logs.

```
logs:CreateLogStream
logs:CreateLogGroup
logs:DescribeLogGroups
logs:PutLogEvents
```

For more information about adding a service role, see [Adding a service role with permissions to deploy backend resources](amplify-service-role.md). For more information about deploying server-side rendered apps, see [Deploying server-side rendered applications with Amplify Hosting](server-side-rendering-amplify.md).

You can view the Amplify Hosting compute logs for an SSR application in the CloudWatch console or in the Amplify console. Use the following instructions to view the logs in the Amplify console. 

**To view CloudWatch logs for an SSR application in the Amplify console**

1. Sign in to the AWS Management Console and open the [Amplify console](https://console.aws.amazon.com/amplify/).

1. Choose the SSR app to view the CloudWatch logs for.

1. In the navigation pane, choose **Monitoring**, then choose **Hosting compute logs**.

1. On the **Hosting compute logs** page, search and select a CloudWatch log group for a specific branch.