View a markdown version of this page

CloudWatch metrics - AWS Amplify

CloudWatch metrics

Welcome to the new AWS Amplify

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

WebRequests

Count

The number of requests to your Amplify endpoint in a given period.

4xx errors

Web4xxErrors

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

Web5xxErrors

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

WebDataTransferOut

Bytes

The total number of bytes that your app transferred out to clients.

Latency (TTFB)

WebLatency

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

WebCacheHitRate

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

ComputeDuration

Milliseconds

The time that your server code’s instances were active. This value is not the time of a single request.

Memory usage

ComputeMaxMemoryUsed

Megabytes

The maximum memory used by your server code.

CPU time

ComputeCpuTime

Milliseconds

The total amount of time that your server code spends processing a request.

Invocations

ComputeInvocations

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 ComputeType dimension reports SSR and middleware invocations separately.

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

AppName, EnvironmentName

Filters metrics by app name and environment. For example, you can filter metrics for the production environment of the app my-app. Amplify doesn’t publish traffic metrics with AppName alone.

Traffic metrics

AppName, EnvironmentName, RoutingTarget

Filters metrics by the portion of traffic that a gradual rollout routes to each target, such as current or new. During a gradual rollout, Amplify publishes every traffic metric except WebCacheHitRate with this dimension set. For more information, see Gradual deployments.

Runtime metrics

AppName

Filters metrics by app name.

Runtime metrics

AppName, EnvironmentName

Filters metrics by app name and environment.

Runtime metrics

AppName, EnvironmentName, ComputeType

Filters metrics by app name, environment, and compute type. The ComputeType dimension has the values SSR and Middleware.

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 grant denied.

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 Sum, Average, Minimum, or Maximum statistic.

Unit: Count

BackendDataTransferOut

The number of bytes your backend sent in its responses. Use the Sum statistic.

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 Average or Maximum statistic.

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 Average or Maximum statistic.

Unit: Bytes

Dimensions for backend metrics

The following table lists the dimensions of backend metrics.

Dimension Description

AppName

The name of your app.

EnvironmentName

The name of the environment, such as production or preview.

Branch

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

AWS/AmplifyGen3

AWS/WAFV2

Region

The AWS Region of your app

US East (N. Virginia) (us-east-1)

Metric names

WafAllowedRequests, WafBlockedRequests, WafTotalRequests

The AWS WAF metrics, such as AllowedRequests and BlockedRequests

Filter by app and environment

Yes, with AppName and EnvironmentName

No. The metrics cover all environments of the app. Filter by the protection pack name, with the WebACL dimension.

Split web and backend requests

Yes, with the Surface dimension

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

AppName

Filters metrics by app name.

AppName, EnvironmentName

Filters metrics by app name and environment. For example, you can filter metrics for the production environment of the app my-app.

AppName, EnvironmentName, Rule

Filters metrics by app name, environment, and AWS Managed Rules group. For example, you can filter metrics for the production environment of the app my-app by the known bad inputs rule group.

AppName, EnvironmentName, Country

Filters metrics by app name, environment, and country of origin. For example, you can filter metrics for the production environment of the app my-app for requests from the United States.

AppName, EnvironmentName, Surface

Filters metrics by app name, environment, and whether the request was to the web part of your app (web) or to its backend (backend).

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

AppName, EnvironmentName

During a gradual rollout, every traffic metric except WebCacheHitRate also has AppName, EnvironmentName, RoutingTarget.

Runtime metrics

AppName

AppName, EnvironmentName

AppName, EnvironmentName, ComputeType

Backend metrics

AppName, EnvironmentName, Branch

Firewall metrics (Amplify managed firewall)

AppName

AppName, EnvironmentName

AppName, EnvironmentName, Country

AppName, EnvironmentName, Rule

AppName, EnvironmentName, Surface (web or backend)

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.

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. In the navigation bar, choose the AWS Region of your app.

  3. In the navigation pane, choose Metrics, and then choose All metrics.

  4. Choose the AWS/AmplifyGen3 namespace.

  5. Choose a dimension set, such as AppName, EnvironmentName.

  6. 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 ComputeInvocations when 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 WebLatency when latency increases. You can use this alarm to know when to investigate your most recent deployment.

  • An alarm on Backend5xxErrors when 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.

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. In the navigation bar, choose the AWS Region of your app.

  3. In the navigation pane, choose Metrics, and then choose All metrics.

  4. Choose the AWS/AmplifyGen3 namespace, and then choose the AppName, EnvironmentName, Branch dimension set.

  5. For the branch, select BackendRequests and Backend5xxErrors, or the metric that shows the problem.

  6. Set the period to 1 minute.

  7. 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.