Skip to main content

More Info:

AWS S3 Buckets configuration changes should be monitored using CloudWatch alarms.

Risk Level

Medium

Address

Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • AWS Well Architected Framework
  • BSI C5 (Germany)
  • Brazil LGPD
  • CCPA / CPRA (California)
  • CIS AWS
  • CIS Critical Security Controls v8
  • CMMC 2.0
  • CSA Cloud Controls Matrix v4
  • Cloudanix Best Practice
  • DPDPA
  • Digital Operational Resilience Act (EU)
  • Essential 8
  • HITRUST CSF
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST
  • NIST CSF
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • PCI
  • SOC2
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

Below are concise, console-based steps to enable an S3 bucket changes alarm using CloudWatch and CloudTrail.

1. Ensure CloudTrail Is Enabled and Logging to CloudWatch Logs

  1. In the AWS Console, go to CloudTrail.
  2. In the left menu, select Trails.
  3. If you already have a trail:
    • Click on the trail name.
    • Under CloudWatch Logs, confirm:
      • CloudWatch Logs log group is set.
      • An IAM role is attached for CloudTrail to send logs to CloudWatch Logs.
    • If not set, click Edit, then:
      • Set CloudWatch Logs to Enabled.
      • Choose or create a Log group.
      • Choose or create a suitable IAM role.
      • Save changes.
  4. If you do not have a trail:
    • Click Create trail.
    • Name the trail.
    • For Storage location, choose/create an S3 bucket.
    • For CloudWatch Logs, set to Enabled, and pick/create a log group and IAM role.
    • Ensure Management events (Read and Write) are enabled.
    • Create the trail.

2. Create a Metric Filter for S3 Bucket Changes

You will filter CloudTrail events that represent S3 bucket changes (such as PutBucketAcl, PutBucketPolicy, etc.).
  1. Go to CloudWatch in the console.
  2. In the left menu, select Logs → Log groups.
  3. Click the log group used by CloudTrail (e.g., /aws/cloudtrail/logs).
  4. Choose the Metric filters tab.
  5. Click Create metric filter (or Add metric filter).
  6. In Filter pattern, use something like:
    (Adjust the event list to your policy as needed.)
  7. Click Next.
  8. Under Assign metric, set:
    • Filter name: e.g., S3BucketChangesFilter.
    • Metric namespace: e.g., Security/CloudTrail.
    • Metric name: e.g., S3BucketChanges.
    • Metric value: 1.
  9. Click Next, then Create metric filter.

3. Create a CloudWatch Alarm for S3 Bucket Changes

  1. In CloudWatch, go to Alarms → All alarms.
  2. Click Create alarm.
  3. Click Select metric.
  4. Choose Browse → go to the namespace you set (e.g., Security/CloudTrail) → select the S3BucketChanges metric.
  5. Click Select metric.
  6. Configure the alarm:
    • Statistic: Sum.
    • Period: e.g., 5 minutes (or as required).
    • Threshold type: Static.
    • Condition: Greater/Equal to 1.
  7. Click Next.
  8. Under Notification:
    • Select an existing SNS topic or click Create new topic.
    • Enter an email endpoint or other subscribers as needed.
  9. Click Next, give the alarm a name, e.g., Alarm-S3BucketChanges, and optional description.
  10. Click Next, then Create alarm.

Once complete, whenever S3 bucket configuration changes (covered by your filter) occur, CloudTrail logs them, the metric filter increments the S3BucketChanges metric, and the CloudWatch alarm triggers and sends a notification.
Below is one concrete way to implement an “S3 bucket changes” CloudWatch alarm using AWS CLI:Goal: Alarm whenever someone changes S3 bucket configuration, such as ACLs/policies.
This uses CloudTrail → CloudWatch Logs → Metric Filter → CloudWatch Alarm.

0. Prerequisites

  • You have an S3 bucket with CloudTrail logs (or will create a new trail).
  • You have (or will create) a CloudWatch Logs log group for CloudTrail.
  • You have an SNS topic ARN to send the alarm notification to (or will create one).
I’ll include all commands.

1. Create / Configure CloudTrail to Send to CloudWatch Logs

1.1 Create the CloudWatch Logs log group (if not exists)

1.2 Create IAM role for CloudTrail to put logs into CloudWatch Logs

Trust policy:
Permissions policy:

1.3 Create (or update) the CloudTrail trail


2. Create a Metric Filter for S3 Bucket Changes

We’ll match CloudTrail events that modify bucket configuration (common examples: PutBucketAcl, PutBucketPolicy, PutBucketCors, PutBucketLifecycleConfiguration, etc.).

2.1 Define the metric filter

2.2 Create the metric filter


3. Create an SNS Topic for Alarm Notifications (if needed)

(You must confirm the subscription email.)

4. Create the CloudWatch Alarm

Alarm if any bucket-change event occurs in a 5‑minute period.

5. Validate

  1. Make a bucket change (e.g., modify ACL or bucket policy).
  2. Check:
    • CloudTrail logs show the event.
    • The metric Security/S3 : S3BucketChangesCount increases.
    • The S3BucketChangesAlarm moves to ALARM state and sends an SNS notification.
This fully enables an alarm on S3 bucket configuration changes using CloudWatch and AWS CLI.
To detect S3 bucket configuration changes with CloudWatch, you need:
  1. CloudTrail sending logs to a CloudWatch Logs log group
  2. A CloudWatch Logs metric filter for S3 bucket-change events
  3. A CloudWatch alarm on that metric
Below is a step‑by‑step guide plus a Python (boto3) example.

1. Prerequisites

  • boto3 installed and configured with credentials/region:
  • An existing CloudTrail trail that:
    • Logs management events
    • Delivers to a CloudWatch Logs log group (e.g., /aws/cloudtrail/main)
If CloudTrail is not yet sending to CloudWatch Logs, configure that first (in console or via boto3.cloudtrail.update_trail with CloudWatchLogsLogGroupArn).
This pattern matches S3 bucket configuration changes in CloudTrail logs:

3. Python script to create metric filter + alarm

This script will:
  • Create/overwrite a metric filter on the specified CloudWatch Logs log group
  • Create/overwrite a CloudWatch alarm that fires when ≥ 1 S3 bucket change is detected in a 5‑minute period

4. Summary of remediation steps

  1. Ensure CloudTrail is enabled and sending logs to a CloudWatch Logs log group.
  2. Use the script (or similar boto3 code) to:
    • Add a metric filter on that log group for S3 bucket config‑change events.
    • Create a CloudWatch alarm on that metric (with SNS notifications if desired).
This assumes you already have a CloudTrail trail delivering management events to the CLOUDTRAIL_LOG_GROUP_NAME CloudWatch Logs group; that trail configuration is managed separately. No resources above require forced replacement beyond standard Terraform create/update behavior.To verify, terraform plan should show:
  • + create aws_sns_topic.s3_bucket_changes_topic
  • + create aws_sns_topic_subscription.s3_bucket_changes_email (if kept)
  • + create aws_cloudwatch_log_metric_filter.s3_bucket_changes_filter
  • + create aws_cloudwatch_metric_alarm.s3_bucket_changes_alarm.

Additional Reading: