Access logs for your Amplify app
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.
To help debug issues related to requests or client access to your app, you can use access logs. Amplify turns on access logs by default in the production environment of your app. By default, you get 5% of production access logs in Amazon CloudWatch Logs. Amplify keeps them for 1 week. In all other environments, such as preview, access logs are off until you turn them on. You can turn off access logs in any environment, including production.
Access logs cover your whole app. Requests to your app’s pages and assets and calls to its backend are in the same log, and the surface field tells them apart. For more information, see Access log fields.
Depending on your app usage, you might generate a lot of access logs. You don’t need to send all of them to your account. Instead, you can configure the sampling rate and retention period for your logs. These settings control what percentage of logs Amplify sends to your account and how long the logs persist. This helps you reduce costs while you continue to monitor your app.
You can also send your access logs to a new or existing Amazon S3 bucket for long-term retention and analysis. Amplify doesn’t deliver access logs to Amazon S3 by default in any environment, including production. To use Amazon S3, turn on S3 delivery for each environment.
As with runtime logs, you can sort your logs and download them. You can search your logs by the following status types:
-
2xx
-
3xx
-
4xx
-
5xx
You can also sort your access logs by the HTTP method used to access your app.
Access logs incur charges in your AWS account, including the default delivery in the production environment. CloudWatch Logs charges for ingesting and storing your access logs. If you also deliver access logs to Amazon S3, Amazon S3 charges for storing them. To control costs, adjust the sampling rate and retention period.
Access log destination
When you deliver access logs to CloudWatch Logs, Amplify writes them to a log group with the following name pattern:
/aws/amplifygen3/<app-name>/<environment-name>/access-logs
For example, the access logs for the production environment are in /aws/amplifygen3/<app-name>/production/access-logs.
Backend requests are in the same log group as web requests. Database logs are in a separate log group. For more information, see Database logs.
Access log fields
Amplify writes each access log line as a JSON object. The surface field is web for pages and assets, or backend for calls to /rest, /rest/rpc, and /auth. To filter on a field, use --filter '{ $.<field> = "<value>" }', which uses CloudWatch Logs filter syntax and is case-sensitive.
The following table lists the fields.
| Field | Appears on | Description |
|---|---|---|
|
|
Both |
The Amazon Resource Name (ARN) of the environment, followed by the destination, |
|
|
Both |
The time of the request. |
|
|
Both |
The part of your app that served the request: |
|
|
Both |
The ID of the request. On a web line, it’s the page’s Amazon CloudFront ID, which is also the |
|
|
Both |
The IP address of the client. |
|
|
Both |
The user agent of the client. |
|
|
Both |
The HTTP method of the request. |
|
|
Both |
The path of the request. |
|
|
Both |
The query string of the request. |
|
|
Both |
The host of the request. |
|
|
Both |
The protocol of the request. |
|
|
Both |
The |
|
|
Both |
The size of the request, in bytes. |
|
|
Both |
The HTTP status code of the response. |
|
|
Both |
The size of the response, in bytes. |
|
|
Both |
The content type of the response. |
|
|
Both |
The total time to serve the request, in milliseconds. |
|
|
Web |
The country of the client. |
|
|
Web |
The time to first byte, in milliseconds. |
|
|
Web |
The origin first byte latency, in milliseconds. |
|
|
Web |
The Amazon CloudFront edge location that served the request. |
|
|
Web |
The cache status of the request. |
|
|
Backend |
The value of the |
|
|
Backend |
The backend branch that served the call. |
|
|
Backend |
The code of the error, such as |
|
|
Backend |
The credential that the call sent. For example, |
|
|
Backend |
The role that the call ran as, such as |
|
|
Backend |
Whether the backend accepted the call’s credential: |
|
|
Backend |
The auth event on an |
|
|
Backend |
The ID of the user who made the call. On the call that a user makes to sign in or sign up, it’s the ID of that user. |
|
|
Backend |
The ARN of the AWS identity that made the call. It appears when |
|
|
Backend |
The result of the email that an |
|
|
Backend |
The message ID of the email that the |
|
|
Backend |
The number of rows that a Data API call returned. |
For anon calls, the client_ip and host fields in backend access logs aren’t verified. Don’t use them to identify who made a call.
What error_reason means
The error_reason field is on backend lines only. It holds the code of the error, such as the SQL state (SQLSTATE) code 42501 or the Data API code PGRST116. It’s absent on success.
On a 5xx response, it holds a general value such as internal_server_error. For a statement timeout, the response body and the database log show the 57014 code. It can also hold one of the following values:
-
throttled– A rate limit or a capacity limit held the request back. -
unavailable– Something on the request path couldn’t serve the request right now. A retry might succeed. -
internal_server_error– A server error. -
invalid_token,expired, ormalformed– The backend refused the credential.
For more information about Data API error codes, see PostgREST error codes
A unique, foreign key, or exclusion constraint can refuse a write. So can a row-level security check. When one does, your backend returns 409 with WRITE_CONFLICT. A write that runs as service_role gets the SQLSTATE of the cause, such as 23505, instead of WRITE_CONFLICT. The database log has the real SQLSTATE, such as 23505.
A statement that runs past its statement_timeout returns 500, and the response body’s code is 57014. Read the database lines for that minute.
The following AWS Command Line Interface (AWS CLI) command lists the failed backend calls of the last hour:
aws amplifygen3 logs get --log-type access -e production --since 1h --filter '{ $.surface = "backend" && $.status_code >= 400 }'
Configure access logs in the console
Use the following procedure to turn on access logs for an environment where they are off, such as preview. You can also use it to send your access logs to Amazon S3.
-
Sign in to the Amplify console at https://us-east-2.console.aws.amazon.com/amplifygen3/home.
-
Choose an app.
-
In the left navigation pane, choose Logs.
-
At the top of the Logs page, choose the environment. By default, the page shows the production environment.
-
Choose Enable log delivery for CloudWatch logs.
-
(Optional) The default sampling rate is 5%, which gives you enough information to monitor your app. If you want, you can change the sampling rate.
-
(Optional) The default retention period is 1 week. You can modify the retention period from 1 day to never expire.
-
(Optional) To send your access logs to an S3 bucket, choose Additional delivery options and do the following:
-
Select Amazon S3 to send your access logs to an S3 bucket.
-
For Sampling rate, enter a sampling rate from 0 to 100 percent. This is the percentage of logs from your Amplify app that Amplify sends to your S3 bucket. If you use the default rate of 5% when you turn on access log delivery, Amplify sends 5% of all your logs to your S3 bucket. We recommend a sampling rate of 100% for delivery to Amazon S3. A higher sampling rate stores more logs and increases your Amazon S3 storage charges.
-
For S3 bucket, select a bucket. Choose Service managed bucket to have Amplify create a bucket on your behalf, or choose Custom bucket and enter an S3 bucket that you own. You can choose Browse S3 to view all the buckets in this AWS Region.
-
-
Choose Enable.
Configure access log delivery using the CLI
Use aws amplifygen3 logs edit to set the access log sampling rate for each destination. The rate is the percentage of requests (0 to 100) recorded in the logs sent to that destination. A rate of 0 turns delivery to that destination off. Settings that you don’t pass stay the same. Access logs are on by default in the production environment and off by default in all other environments.
Logs sent to Amazon S3 need a bucket. Name a bucket that you own with --access-log-s3-bucket, as a bucket name or an ARN, or pass --managed-bucket to use the app’s managed bucket. If you use your own bucket, its bucket policy must let CloudWatch Logs (delivery.logs.amazonaws.com) write to it. The following AWS CLI command delivers access logs to CloudWatch Logs at 5% and to an S3 bucket that you own at 100%:
aws amplifygen3 logs edit --env production \ --access-log-cwl-sampling-rate 5 \ --access-log-s3-sampling-rate 100 \ --access-log-s3-bucket arn:aws:s3:::amzn-s3-demo-bucket
The app’s environments share one managed bucket per log type, and Amplify creates it if none exists yet. The following AWS CLI command delivers access logs to the app’s managed bucket instead:
aws amplifygen3 logs edit --env production \ --access-log-cwl-sampling-rate 5 \ --access-log-s3-sampling-rate 100 \ --managed-bucket
To turn off access logs for an environment, including production, set both rates to 0. Run the following AWS CLI command:
aws amplifygen3 logs edit --env <environment> --access-log-cwl-sampling-rate 0 --access-log-s3-sampling-rate 0
To view the access logs for an environment, run the following AWS CLI command:
aws amplifygen3 logs get --log-type access --env <environment>
For all log options, including firewall and database logs, see the CLI reference.
Sampling and defaults
By default, 5% of production access logs go to CloudWatch Logs. Access logs are off in other environments. Backend lines use the same rate.
Rate-limited auth routes keep every line at any rate above 0. These include the routes that users call to sign in, sign up, and change or reset a password. They also include the routes for email change and verification, token mode, and OAuth 2.0. The GET /auth/token route isn’t one of them.
When a page’s backend calls send the page’s ID in x-amplify-trace-id, sampling keeps or drops them together with the page.
A rate change takes effect in up to 3 minutes. The new rate applies only to requests served after the change.
To see the sampling rates and then capture every request while you debug, run the following AWS CLI commands. Replace <environment-name> with the name of the environment, such as production:
aws amplifygen3 logs-config get -e <environment-name> aws amplifygen3 logs-config edit --access-log-cwl-sampling-rate 100 -e <environment-name>
CloudWatch Logs charges you to ingest and store access logs and database logs. For more information, see Amazon CloudWatch pricing
Find a backend request by its request ID
To find one backend call, filter on request_id. Use the value of the response’s x-request-id header, or the client SDK’s error.requestId. Replace <request-id> with the request ID:
aws amplifygen3 logs get --log-type access -e production --since 1h --filter '{ $.request_id = "<request-id>" }'
If the command returns no line, either the call is outside the time window or sampling dropped it.
Find the database lines for a backend call
Database lines have no request ID, so match them to a call by branch, time, and SQLSTATE. From the call’s backend access line, note branch, event_timestamp, and error_reason. Then read the database lines of the same branch for the same minute. Filter on branch and sql_state_code.
When error_reason is WRITE_CONFLICT, the database line has the real SQLSTATE, such as 23505. In that case, filter on error_severity
ERROR instead of sql_state_code.
To read the database lines for the call, run the following AWS CLI command. Replace <start-time> and <end-time> with ISO 8601 times around the call, such as 2026-11-20T18:04:00Z. Replace <branch> with the branch value from the access line, and <sql-state-code> with the SQLSTATE from error_reason or, for a 5xx call, from the response body:
aws amplifygen3 logs get --log-type database -e production --start-time <start-time> --end-time <end-time> --filter '{ $.branch = "<branch>" && $.sql_state_code = "<sql-state-code>" }'
Database lines can take up to 3 minutes to arrive. For more information, see Database logs.
Follow one page load through your app
A page’s backend calls share the page’s ID as trace_id when your server code sends the page request’s x-amz-cf-id value in the x-amplify-trace-id header. The page’s ID is the request_id on its web line. The following TypeScript example for Next.js sends the header:
import { headers } from 'next/headers' import { createClient } from '@aws-amplifygen3/backend-client-js' const pageId = (await headers()).get('x-amz-cf-id') const backend = createClient(process.env.AMPLIFY_BACKEND_URL, process.env.AMPLIFY_BACKEND_PUBLISHABLE_KEY, { global: { headers: pageId ? { 'x-amplify-trace-id': pageId } : {} }, })
To list the backend calls of one page load, run the following AWS CLI command. Replace <page-id> with the request_id of the page’s web line:
aws amplifygen3 logs get --log-type access -e production --since 1h --filter '{ $.trace_id = "<page-id>" }'
For a call that failed, read the database logs for the same minute. For more information, see Database logs. If the problem started after a deployment, read that deployment’s log. For more information, see View your build logs.
The following example shows the web line, a backend line, and the database line for a save that failed because a note with the same title exists:
{"event_timestamp":1795003859910,"surface":"web","request_id":"EXAMPLEcfId4Lb2Qx9Wm7Tz3Hp8Kd6Ns1Vf5Rj0Yc2Ue==","method":"POST","path":"/notes","status_code":200,"time_taken_ms":412} {"event_timestamp":1795003859980,"surface":"backend","request_id":"EXAMPLEa1Bc2De3Fg4Hi5Jk6Lm7No8Pq9Rs0Tu1Vw2Xy3Za4Bc5De6Fg7Hi8Jk9==","branch":"production","trace_id":"EXAMPLEcfId4Lb2Qx9Wm7Tz3Hp8Kd6Ns1Vf5Rj0Yc2Ue==","method":"POST","path":"/rest/notes","status_code":409,"error_reason":"WRITE_CONFLICT","auth_method":"bearer","auth_role":"authenticated","auth_result":"success","time_taken_ms":38} {"event_timestamp":1795003860000,"branch":"production","error_severity":"ERROR","sql_state_code":"23505","event_message":"duplicate key value violates unique constraint \"notes_title_key\"","user_name":"api","session_id":"EXAMPLE.1a2b"}