CloudWatch metrics
Amplify now puts hosting, a Postgres database, and sign-in in one AWS account. Deploy from your terminal or from Git, check every change in a preview first, and roll back in one step if something breaks.
Looking for Amplify Hosting? See the Amplify Hosting User Guide.
You can monitor your app with the metrics that Amplify publishes to Amazon CloudWatch (CloudWatch). This topic describes these metrics, how to view them in the CloudWatch console, and how to create alarms from them. For instructions on viewing your metrics in the Amplify console, see View your metrics.
Metrics for your app
You can view your Amplify app metrics in CloudWatch in the AWS/AmplifyGen3 namespace. The metrics are in the AWS Region of your app. Traffic metrics are available for all apps. Runtime metrics are available only for apps with a server component, such as apps that use server-side rendering (SSR). If your app uses the Amplify managed firewall, Amplify also publishes firewall metrics, such as WafAllowedRequests and WafTotalRequests, in the same namespace. For more information, see Firewall metrics.
Web (traffic) metric names start with Web, such as WebLatency, and most backend metric names start with Backend, such as BackendLatency.
The following tables list each metric’s name and its CloudWatch metric name.
Traffic metrics
Traffic metrics are available for all environments of your Amplify app. For example, you can monitor the 4xx errors metric to measure client-side errors, or the latency metric to measure the overall responsiveness of your app.
The following table lists the traffic metrics.
| Name | CloudWatch metric name | Unit | Description |
|---|---|---|---|
|
Requests |
|
Count |
The number of requests to your Amplify endpoint in a given period. |
|
4xx errors |
|
Count |
The number of client-side errors captured in a given period. The Amplify console shows this metric as an error rate (a percentage). |
|
5xx errors |
|
Count |
The number of server-side errors captured in a given period. The Amplify console shows this metric as an error rate (a percentage). |
|
Bandwidth |
|
Bytes |
The total number of bytes that your app transferred out to clients. |
|
Latency (TTFB) |
|
Milliseconds |
The time to first byte (TTFB). TTFB starts when a browser requests your app’s endpoint. It ends when the browser receives the first byte from Amplify. The console graphs the p50 and p99 percentiles. |
|
Cache hit rate |
|
Percent |
The percentage of requests served from the cache. For example, if there were 50 requests and 40 were cache hits, the cache hit rate is 80%. |
Runtime metrics
Runtime metrics are available only for apps with a server component, such as SSR apps. For example, if you built a client-side React app, these metrics aren’t available. If your app has a server component, runtime metrics are available for all environments of your app.
The following table lists the runtime metrics.
| Name | CloudWatch metric name | Unit | Description |
|---|---|---|---|
|
Execution duration |
|
Milliseconds |
The time that your server code’s instances were active. This value is not the time of a single request. |
|
Memory usage |
|
Megabytes |
The maximum memory used by your server code. |
|
CPU time |
|
Milliseconds |
The total amount of time that your server code spends processing a request. |
|
Invocations |
|
Count |
The number of times that your server code is invoked. This number includes successful invocations and invocations that result in a function error. The |
Dimensions
You can filter metrics by dimension. A dimension set is the combination of dimensions that Amplify publishes a metric with. To read a metric or create an alarm on it, you must specify all the dimensions of one of its sets. The EnvironmentName value is the name of the environment, such as production or preview.
The following table lists the dimension sets for each type of metric.
| Metric type | Dimension set | Description |
|---|---|---|
|
Traffic metrics |
|
Filters metrics by app name and environment. For example, you can filter metrics for the |
|
Traffic metrics |
|
Filters metrics by the portion of traffic that a gradual rollout routes to each target, such as |
|
Runtime metrics |
|
Filters metrics by app name. |
|
Runtime metrics |
|
Filters metrics by app name and environment. |
|
Runtime metrics |
|
Filters metrics by app name, environment, and compute type. The |
Backend metrics
If your app has a backend, you also get metrics for the requests to your backend. They can take a few minutes to appear. A request metric appears after the first request that it counts.
The following backend metrics are supported:
| Metric | Description |
|---|---|
|
BackendRequests |
The number of requests to your backend in a given period. Unit: Count |
|
Backend4xxErrors |
The number of backend requests that returned a 4xx status code, such as a request that a row-level security rule or a missing Unit: Count |
|
Backend5xxErrors |
The number of backend requests that returned a 5xx status code. Unit: Count |
|
BackendLatency |
The time your backend took to respond to a request. Unit: Milliseconds |
|
BackendRowsReturned |
The number of rows that a request to the Data API returned. This metric is published as a statistic set, with the sum, count, minimum, and maximum for each period. Use the Unit: Count |
|
BackendDataTransferOut |
The number of bytes your backend sent in its responses. Use the Unit: Bytes |
|
AuthSuccessCount |
The number of backend requests that your backend didn’t refuse for authentication. Unit: Count |
|
BackendThrottledCount |
The number of backend requests that a rate limit or a capacity limit held back with a 429 status code. Unit: Count |
|
AuthFailureCount |
The number of backend requests that your backend refused for authentication, such as a request with a missing or invalid publishable key or an expired user token. Unit: Count |
|
DatabaseConnections |
The number of connections open on your backend’s database at each sample. Some of these connections serve your backend itself, such as for Data API requests. So the count can be higher than the number of connections your app opens. This metric has one data point every 5 minutes. Each data point’s timestamp is the start of its 5-minute window. Use a period of 300 seconds or more, with the Unit: Count |
|
DatabaseStorageBytes |
The storage that your backend’s database uses at each sample. This metric has one data point every 5 minutes. Each data point’s timestamp is the start of its 5-minute window. Use a period of 300 seconds or more, with the Unit: Bytes |
Dimensions for backend metrics
The following table lists the dimensions of backend metrics.
| Dimension | Description |
|---|---|
|
|
The name of your app. |
|
|
The name of the environment, such as |
|
|
The backend branch, which is the last part of the branch ARN. |
To find the Branch value, run the following AWS Command Line Interface (AWS CLI) command and read the NAME column. Replace
environment-name
with the name of the environment:
aws amplifygen3 branch list -e environment-name
Firewall metrics
Your firewall metrics depend on which firewall your app uses. The Amplify managed firewall and a custom firewall publish different metrics, in different namespaces and Regions. The following table shows the differences.
| Amplify managed firewall | Custom firewall | |
|---|---|---|
|
Namespace |
|
|
|
Region |
The AWS Region of your app |
US East (N. Virginia) ( |
|
Metric names |
|
The AWS WAF metrics, such as |
|
Filter by app and environment |
Yes, with |
No. The metrics cover all environments of the app. Filter by the protection pack name, with the |
|
Split web and backend requests |
Yes, with the |
No |
Metrics for the Amplify managed firewall
If your app uses the Amplify managed firewall, Amplify publishes firewall metrics in the AWS/AmplifyGen3 namespace. These metrics appear after your app is deployed and starts to receive HTTP requests. Until your app receives traffic, there are no metrics to show.
The following table lists the firewall metrics.
| Metric | Description |
|---|---|
|
WafAllowedRequests |
Requests that the firewall allowed Unit: Count |
|
WafBlockedRequests |
Requests that the firewall blocked Unit: Count |
|
WafTotalRequests |
All requests that the firewall evaluated Unit: Count |
The following table lists the dimensions that you can use to filter firewall metrics.
| Dimension set | Description |
|---|---|
|
|
Filters metrics by app name. |
|
|
Filters metrics by app name and environment. For example, you can filter metrics for the |
|
|
Filters metrics by app name, environment, and AWS Managed Rules group. For example, you can filter metrics for the |
|
|
Filters metrics by app name, environment, and country of origin. For example, you can filter metrics for the |
|
|
Filters metrics by app name, environment, and whether the request was to the web part of your app ( |
Firewall metrics don’t have a branch dimension. The Rule, Country, and Surface dimensions exist only for the Amplify managed firewall.
Metrics for a custom firewall
If your app uses a custom firewall, AWS WAF publishes the metrics for your protection pack in the AWS/WAFV2 namespace, in the US East (N. Virginia) Region (us-east-1), with the protection pack name as the WebACL dimension. The AWS/AmplifyGen3 firewall metrics do not include traffic that a custom firewall evaluates.
A custom firewall’s metrics cover all environments of your app, web and backend together. AWS WAF counts requests for the whole protection pack, and no AWS/WAFV2 dimension separates environments or web and backend requests. To tell them apart, view sampled requests, and check the host of each request. For more information, see AWS WAF metrics in the AWS WAF Developer Guide.
Which dimensions does each metric use?
The following table lists the dimension sets for each type of metric.
| Metrics | Dimension sets |
|---|---|
|
Traffic (web) metrics |
During a gradual rollout, every traffic metric except |
|
Runtime metrics |
|
|
Backend metrics |
|
|
Firewall metrics (Amplify managed firewall) |
|
Firewall metrics don’t have a branch dimension.
View metrics in the CloudWatch console
You can also view your app metrics in the CloudWatch console in the AWS/AmplifyGen3 namespace.
-
Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
-
In the navigation bar, choose the AWS Region of your app.
-
In the navigation pane, choose Metrics, and then choose All metrics.
-
Choose the AWS/AmplifyGen3 namespace.
-
Choose a dimension set, such as AppName, EnvironmentName.
-
Select the checkbox next to each metric that you want to graph.
Create alarms from your metrics
You can create CloudWatch alarms on the app metrics in the AWS/AmplifyGen3 namespace. For example, you can create the following alarms:
-
An alarm on
ComputeInvocationswhen invocations cross a threshold. You can use this alarm to prepare the dependencies behind your app, such as a headless CMS or other backend services, for additional load. -
An alarm on
WebLatencywhen latency increases. You can use this alarm to know when to investigate your most recent deployment. -
An alarm on
Backend5xxErrorswhen it’s above 0 for 5 minutes in production. -
An alarm on
BackendThrottledCount, to know when backend requests are throttled. -
An alarm on a spike in
AuthFailureCount, to know when many backend requests fail authentication.
The following AWS CLI command creates an alarm for the production backend of my-notes. The alarm goes into the ALARM state when the backend returns 5xx errors for 5 minutes in a row. Replace
branch
with your Branch value:
aws cloudwatch put-metric-alarm --alarm-name my-notes-backend-5xx --namespace AWS/AmplifyGen3 --metric-name Backend5xxErrors --dimensions Name=AppName,Value=my-notes Name=EnvironmentName,Value=production Name=Branch,Value=branch --statistic Sum --period 60 --evaluation-periods 5 --threshold 0 --comparison-operator GreaterThanThreshold --treat-missing-data notBreaching
The production environment’s branch is named production.
A minute with no 5xx errors has no data point. The --treat-missing-data notBreaching option keeps the alarm out of the ALARM state when there’s no traffic or no errors.
For more information, see What error_reason means.
For more information, see Using Amazon CloudWatch alarms in the Amazon CloudWatch User Guide.
Find when a backend problem started
Each backend branch has its own series, under the AppName, EnvironmentName, Branch dimension set. To find the minute when a problem started, graph the branch’s metrics by the minute.
-
Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
-
In the navigation bar, choose the AWS Region of your app.
-
In the navigation pane, choose Metrics, and then choose All metrics.
-
Choose the AWS/AmplifyGen3 namespace, and then choose the AppName, EnvironmentName, Branch dimension set.
-
For the branch, select
BackendRequestsandBackend5xxErrors, or the metric that shows the problem. -
Set the period to 1 minute.
-
Find the first minute where the value changes.
A minute with no data point counted nothing for that metric. The latest minute can take up to 3 minutes to be complete. Compare errors with requests, not only the error count.
To graph an error rate, use the metric math expression 100 * FILL(errors, 0) / requests, with both metrics at Sum.
To compare that minute with your deployment times, run the following AWS CLI command. Replace
environment-name
with the name of the environment:
aws amplifygen3 deployment list -e environment-name
Then read the logs of that branch for that minute. For more information, see Find the database lines for a backend call and What error_reason means.