Firewall logs
You can use firewall logs to understand potentially malicious requests to your app. The logs that you see, and the permissions that you need, depend on which firewall your app uses: the Amplify managed firewall or a custom firewall.
The following table lists the logs for each firewall.
| Firewall | Logs |
|---|---|
|
Amplify managed firewall |
Off by default. Turn on delivery for each environment to CloudWatch Logs, Amazon S3, or both. |
|
Custom firewall |
Off by default. Turn on logging for the protection pack to a CloudWatch Logs log group. Until then, you can view a sample of recent requests. |
View firewall logs
To view firewall logs, open the Logs page for your app, and then choose the Firewall tab. The Logs page shows one environment at a time. The Firewall tab uses the environment that you select, but only some firewall logs belong to one environment. The following table shows which firewall logs use the selected environment.
| Firewall logs | Uses the selected environment? |
|---|---|
|
Amplify managed firewall logs |
Yes. The tab shows the log group of the selected environment. |
|
Custom firewall logs |
No. The tab shows the log group of the protection pack, which covers the whole app. |
|
Custom firewall sample |
No. The tab shows a sample for the whole app from the last 3 hours. |
The following table shows what the Firewall tab shows in each case.
| Case | What you see |
|---|---|
|
Logs are delivered to CloudWatch Logs |
A table of log lines for the selected environment. |
|
No log lines in the selected time range |
A No lines message, with a link to the log group in CloudWatch. |
|
Amplify managed firewall, logs turned off |
An Enable firewall logs button. For more information, see Turn on logs for the Amplify managed firewall. |
|
Custom firewall, no log destination |
A free sample of requests from the last 3 hours, marked as not every request. The sample shows up to 100 requests for each rule, plus up to 100 requests that no rule matched. |
|
Custom firewall, empty sample |
An Enable custom firewall logs button. For more information, see Turn on logs for a custom firewall. |
Turn on logs for the Amplify managed firewall
Firewall log delivery is off by default. You turn it on for each environment, and you choose the following settings:
-
Destination: CloudWatch Logs, Amazon S3, or both. For Amazon S3, Amplify can create a bucket for you, or you can choose your own bucket.
-
Sampling rate: A value from
0to100for each destination, which sets what percentage of requests is logged. Set the rate to100to log every request. -
Blocked requests only: Logs only the requests that the firewall blocked, instead of every request that the firewall evaluates.
-
Retention period: How long CloudWatch Logs keeps the logs.
Only requests that your app receives after you turn on delivery are logged. Log lines can take a few minutes to appear. Amplify delivers CloudWatch Logs firewall logs to the log group /aws/amplifygen3/app-name/environment-name/waf.
Use the following procedure to turn on firewall log delivery in the Amplify console:
-
Sign in to the AWS Management Console and open the Amplify console.
-
On the apps page, choose the name of your app.
-
In the navigation pane, choose Logs.
-
Select the environment to turn on logs for.
-
Choose the Firewall tab.
-
Choose Enable firewall logs.
-
To deliver logs to CloudWatch Logs, select the CloudWatch option, and then set the sampling rate and retention period.
-
(Optional) To deliver logs to Amazon S3, expand Additional delivery options, select Amazon S3, and then set the sampling rate. For S3 bucket, choose Service managed bucket or Custom bucket.
-
(Optional) To log only blocked requests, select Blocked requests only.
-
Choose Enable.
After delivery starts, the Firewall tab shows the firewall logs for the selected environment. Repeat this procedure for each environment that you want logs for. For the AWS CLI commands that turn on and configure firewall log delivery, see CLI reference.
The following table lists the fields in each log.
| Field | Description |
|---|---|
|
Timestamp ( |
The request time, in milliseconds since the Unix epoch. |
|
Action |
The action of the firewall: |
|
Terminating rule |
The rule that decided the action for the request. |
|
Method |
The HTTP method of the request, such as |
|
Headers |
The headers in the request. The firewall hashes credential headers. |
|
URI |
The request URI. |
|
Country |
The country of origin of the request. |
|
Client IP |
The IP address of the immediate TCP connection that made the request. |
|
Surface |
|
Each firewall log line is a JSON object with camelCase field names. The surface field is web or backend. Firewall lines have no branch field. The following AWS CLI command lists the firewall lines for backend requests:
aws amplifygen3 logs get --log-type firewall -e production --since 24h --filter '{ $.surface = "backend" }'
You cannot change the rules of the Amplify managed firewall. If it blocks a request that your app needs, the log line names the rule that blocked it. To use your own rules, add a custom firewall on the Pro plan or higher. For more information, see Add a custom firewall to your app.
Turn on logs for a custom firewall
A custom firewall does not deliver firewall logs until you turn on logging for its protection pack. Until then, the Firewall tab shows a free sample of recent requests from AWS WAF.
To keep a record of every request that your custom firewall evaluates, turn on logging to a CloudWatch Logs log group. Logging applies to the whole app, not to one environment. AWS WAF delivers logs only to a log group whose name starts with aws-waf-logs-, in US East (N. Virginia) (us-east-1). CloudWatch Logs charges apply. For more information, see Amazon CloudWatch pricing
Use the following procedure to turn on logging for a custom firewall in the Amplify console:
-
Sign in to the AWS Management Console and open the Amplify console.
-
On the apps page, choose the name of your app.
-
In the navigation pane, choose Logs.
-
Choose the Firewall tab.
-
Choose Enable custom firewall logs.
-
For CloudWatch Logs log group, choose Create new log group and enter a name, or choose Use existing log group and select a log group. The name defaults to
aws-waf-logs-protection-pack-name. -
Choose a retention period.
-
Choose Enable.
You can also turn on logging from these pages:
-
Security page: Choose View details, and then choose Enable custom firewall logs.
-
Settings page: In Logs, open the menu for Custom firewall log delivery, and then choose Edit. Select Deliver custom firewall logs to CloudWatch, set the log group and retention period, and then choose Save.
After logging starts, the Firewall tab shows the logs from the log group for every environment that you select. You can also configure logging to Amazon S3 or Amazon Data Firehose on the AWS WAF console. For more information, see Data protection and logging for AWS WAF protection pack (web ACL) traffic in the AWS WAF Developer Guide.
Permissions to monitor your firewall
Permissions for the Amplify managed firewall
The following table lists the permissions that your AWS Identity and Access Management (IAM) identity needs to see metrics and logs for the Amplify managed firewall in the Amplify console.
| Task | Permissions |
|---|---|
|
View metrics |
|
|
View log delivery settings |
|
|
Turn on or change log delivery |
|
|
Deliver logs to a service managed Amazon S3 bucket |
|
|
View logs on the Logs page |
|
Permissions for a custom firewall
The following table lists the permissions that your IAM identity needs to see metrics and logs for a custom firewall in the Amplify console.
| Task | Permissions |
|---|---|
|
View metrics |
|
|
View sampled requests |
|
|
View the logging configuration |
|
|
Turn on logging |
|
|
Turn off logging |
|
|
View logs on the Logs page |
|
For the permissions to add or remove a custom firewall, see Permissions and the web ACL resource policy.
Troubleshoot firewall logs
The following table lists common problems with firewall logs and how to resolve them.
| Problem | Cause | Solution |
|---|---|---|
|
No log lines appear for the Amplify managed firewall |
Logging was off when your app received the requests. Requests that your app receives before logging is on are not logged. |
Turn on logs if they are off, and then send requests to your app again. |
|
No log lines appear for a custom firewall |
Logging is off for the protection pack. Until you turn it on, the Firewall tab shows only a sample of recent requests. |
Turn on logging for the custom firewall. For more information, see Turn on logs for a custom firewall. |
|
There are fewer log lines than requests |
The sampling rate is below |
Check the log delivery settings for the environment. |
|
A request returned HTTP 403, but there is no |
The 403 came from another part of your app, such as your backend or your app code. |
Check the access logs. For more information, see Access logs for your Amplify app. |
|
The firewall allowed a request, but the visitor was sent to a sign-in page |
Access control redirected the visitor after the firewall allowed the request. |
No action is needed. This is expected for an environment with access control. |