Skip to main content

More Info:

AWS VPC Customer/Internet Gateway 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
  • HIPAA
  • HITRUST CSF
  • ISO 27001
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST CSF
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • SOC2
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

Below are console-only steps to configure a CloudWatch alarm that fires when Internet Gateway (IGW) changes occur, based on CloudTrail logs.

Prerequisites

  1. CloudTrail enabled and logging to CloudWatch Logs.
    • If you already have a CloudTrail trail sending events to a CloudWatch Logs log group, skip to Step 2.
    • If not:
      1. Go to CloudTrail console.
      2. In the left menu, select Trails, then Create trail (or edit an existing trail).
      3. In Log events, choose:
        • Management events: Read/Write events → at least Write.
      4. In CloudWatch Logs, Enable:
        • Choose or create a Log group (e.g., /aws/cloudtrail/main).
        • Set an IAM role as prompted.
      5. Save the trail.
You must know the CloudWatch Logs log group name to proceed.

Step 1 – Create a Metric Filter for IGW Changes

  1. Go to CloudWatch console.
  2. In the left menu, choose Logs → Log groups.
  3. Click the CloudTrail log group (e.g., /aws/cloudtrail/main).
  4. Click the Metric filters tab.
  5. Click Create metric filter.
  6. Under Filter pattern, use a pattern that matches Internet Gateway changes. For example:
  7. Click Next.
  8. Under Assign metric:
    • Filter name: IGWChangesFilter
    • Metric namespace: Security/CloudTrail
    • Metric name: InternetGatewayChanges
    • Metric value: 1
    • Default value: leave blank (or 0).
  9. Click Next, then Create metric filter.

Step 2 – Create an Alarm on the Metric

  1. In the same log group’s Metric filters tab, find IGWChangesFilter.
  2. Click the three dots or the Create alarm link for that metric.
  3. This takes you to the Specify metric and conditions page:
    • Verify Metric namespace: Security/CloudTrail
    • Metric: InternetGatewayChanges
  4. Under Conditions:
    • Statistic: Sum
    • Period: 5 minutes (or as desired)
    • Threshold type: Static
    • Whenever metric is: Greater than
    • Threshold value: 0
  5. Click Next.

Step 3 – Configure Notifications

  1. Under Notification:
    • Alarm state trigger: In alarm
    • Select an SNS topic:
      • Choose an existing topic (e.g., security-alerts), or
      • Click Create new topic, give it a name, and enter your email.
  2. If you created a new topic:
    • After finishing, check your email to Confirm subscription.
  3. Click Next.

Step 4 – Name and Create the Alarm

  1. Alarm name: InternetGatewayChangesAlarm
  2. Alarm description: Alarm when Create/Delete/Attach/Detach Internet Gateway occurs via CloudTrail
  3. Review all settings.
  4. Click Create alarm.

Result

Whenever an Internet Gateway is created, deleted, attached, or detached, CloudTrail logs the event, the metric filter increments InternetGatewayChanges, and the CloudWatch alarm goes In alarm (and sends SNS notification).
Below is a minimal, end‑to‑end example of enabling an “Internet Gateway Changes” CloudWatch alarm using the AWS CLI.Assumptions:
  • You already have a CloudTrail trail delivering logs to a CloudWatch Logs log group called /aws/cloudtrail/main.
  • You want an SNS notification when an Internet Gateway is created/attached/detached/deleted.
You can adjust names/regions as needed.

1. Create (or choose) an SNS topic

Note the TopicArn from the output (call it IGW_TOPIC_ARN).Subscribe your email (or other endpoint):
Confirm the subscription from your email.

2. Create a CloudWatch Logs metric filter for Internet Gateway changes

Replace:
  • LOG_GROUP_NAME with your CloudTrail log group (e.g. /aws/cloudtrail/main).
This creates a metric:
  • Namespace: Security
  • Name: InternetGatewayChangesCount
  • Increments by 1 when any of the above events occurs.

3. Create a CloudWatch alarm on that metric

Replace:
  • REGION with your region (e.g. us-east-1).
  • IGW_TOPIC_ARN with the SNS TopicArn from step 1.
This triggers if at least one IGW change occurs in a 5‑minute period.

4. Verify

  • Generate a test event (e.g., create/attach an Internet Gateway).
  • Check:
    • CloudWatch → Logs: metric filter is matched.
    • CloudWatch → Alarms: alarm goes to ALARM state.
    • SNS: notification email is received.
This completes enabling the Internet Gateway Changes alarm using AWS CLI.
Below are the steps and example Python (boto3) code to detect and alarm on Internet Gateway changes using AWS CloudWatch:

1. Prerequisites

  1. You must have:
    • CloudTrail enabled and recording management events.
    • A CloudWatch Logs log group where CloudTrail is delivering events.
      Example name below: /aws/cloudtrail/management
  2. Install and configure boto3:

2. Decide What to Alert On

We want to monitor CloudTrail events for Internet Gateway changes, e.g.:
  • CreateInternetGateway
  • DeleteInternetGateway
  • AttachInternetGateway
  • DetachInternetGateway
The CloudWatch Logs metric filter will look for these in eventName.

3. Python Script Overview

The script will:
  1. Create (or update) a CloudWatch Logs metric filter that:
    • Matches CloudTrail events for the above operations.
    • Publishes a custom metric (e.g. InternetGatewayChanges) in a namespace (e.g. Security).
  2. Create (or update) a CloudWatch alarm that:
    • Triggers whenever the metric is ≥ 1 in a recent period.
    • Sends notification to an SNS topic (you must have one, or create it).

4. Example Python Code

Replace:
  • YOUR_LOG_GROUP_NAME with your CloudTrail log group (e.g. /aws/cloudtrail/management)
  • YOUR_SNS_TOPIC_ARN with an SNS topic ARN for notifications
  • Adjust region/profile as needed.

5. Validation Steps

  1. Confirm CloudTrail is logging to the specified log group:
    • In the CloudTrail console, open your trail → “CloudWatch Logs” section.
  2. Run the script:
  3. In the AWS console:
    • CloudWatch → Logs → Log groups → select your group → “Metric filters”
      Confirm InternetGatewayChangesFilter exists.
    • CloudWatch → Alarms
      Confirm InternetGatewayChangesAlarm exists and is in OK state.
  4. Test:
    • Create or delete an Internet Gateway (or attach/detach it).
    • After a few minutes, the alarm should go to ALARM and send an SNS notification.

This setup remediates “Internet Gateway Changes Alarm Should Be Enabled” by programmatically ensuring both the metric filter and the alarm are in place.
Substitute:
  • LOG_GROUP_NAME with your CloudTrail log group name.
  • ARN_OF_SNS_TOPIC_OR_OTHER_ACTION with the SNS topic (or other) ARN to notify.
This change does not force replacement of any dependent VPC resources; it only creates/updates CloudWatch resources. After updating Terraform, terraform plan should show creation (or in-place update) of aws_cloudwatch_log_metric_filter.internet_gateway_changes and aws_cloudwatch_metric_alarm.internet_gateway_changes_alarm with the specified threshold and configuration.

Additional Reading: