View a markdown version of this page

Firewall logs - AWS Amplify

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 0 to 100 for each destination, which sets what percentage of requests is logged. Set the rate to 100 to 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:

  1. Sign in to the AWS Management Console and open the Amplify console.

  2. On the apps page, choose the name of your app.

  3. In the navigation pane, choose Logs.

  4. Select the environment to turn on logs for.

  5. Choose the Firewall tab.

  6. Choose Enable firewall logs.

  7. To deliver logs to CloudWatch Logs, select the CloudWatch option, and then set the sampling rate and retention period.

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

  9. (Optional) To log only blocked requests, select Blocked requests only.

  10. 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 (eventTimestamp)

The request time, in milliseconds since the Unix epoch.

Action

The action of the firewall: ALLOW | BLOCK. ALLOW means that the request passed the firewall. BLOCK means that the firewall blocked the request.

Terminating rule

The rule that decided the action for the request. Default_Action means that no rule matched, so the default action of the firewall applied.

Method

The HTTP method of the request, such as GET, POST, or DELETE.

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

web for requests to your app’s pages and assets, or backend for requests to its backend.

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:

  1. Sign in to the AWS Management Console and open the Amplify console.

  2. On the apps page, choose the name of your app.

  3. In the navigation pane, choose Logs.

  4. Choose the Firewall tab.

  5. Choose Enable custom firewall logs.

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

  7. Choose a retention period.

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

cloudwatch:GetMetricData

View log delivery settings

amplifygen3:GetEnvironment

Turn on or change log delivery

amplifygen3:UpdateEnvironment, logs:DeleteRetentionPolicy, and logs:PutRetentionPolicy. The logs permissions set the retention period.

Deliver logs to a service managed Amazon S3 bucket

s3:CreateBucket, s3:ListBucket, s3:PutBucketPolicy, s3:PutBucketPublicAccessBlock, s3:PutBucketVersioning, and s3:PutEncryptionConfiguration

View logs on the Logs page

logs:GetQueryResults, logs:StartQuery, and logs:StopQuery

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

cloudwatch:GetMetricData

View sampled requests

wafv2:GetSampledRequests and wafv2:GetWebACL

View the logging configuration

wafv2:GetLoggingConfiguration

Turn on logging

logs:CreateLogDelivery, logs:DescribeLogGroups, logs:DescribeResourcePolicies, logs:PutResourcePolicy, and wafv2:PutLoggingConfiguration. To create a new log group, also logs:CreateLogGroup. To set the retention period, also logs:DeleteRetentionPolicy and logs:PutRetentionPolicy.

Turn off logging

logs:DeleteLogDelivery and wafv2:DeleteLoggingConfiguration

View logs on the Logs page

logs:GetQueryResults, logs:StartQuery, and logs:StopQuery

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 100, or Blocked requests only is selected.

Check the log delivery settings for the environment.

A request returned HTTP 403, but there is no BLOCK line

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.