More Info:
AWS VPC Customer/Internet Gateway configuration changes should be monitored using CloudWatch alarms.Risk Level
MediumAddress
SecurityCompliance 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
Remediation
Using Console
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
- 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:
- Go to CloudTrail console.
- In the left menu, select Trails, then Create trail (or edit an existing trail).
- In Log events, choose:
- Management events: Read/Write events → at least Write.
- In CloudWatch Logs, Enable:
- Choose or create a Log group (e.g.,
/aws/cloudtrail/main). - Set an IAM role as prompted.
- Choose or create a Log group (e.g.,
- Save the trail.
Step 1 – Create a Metric Filter for IGW Changes
- Go to CloudWatch console.
- In the left menu, choose Logs → Log groups.
-
Click the CloudTrail log group (e.g.,
/aws/cloudtrail/main). - Click the Metric filters tab.
- Click Create metric filter.
-
Under Filter pattern, use a pattern that matches Internet Gateway changes. For example:
- Click Next.
-
Under Assign metric:
- Filter name:
IGWChangesFilter - Metric namespace:
Security/CloudTrail - Metric name:
InternetGatewayChanges - Metric value:
1 - Default value: leave blank (or
0).
- Filter name:
- Click Next, then Create metric filter.
Step 2 – Create an Alarm on the Metric
- In the same log group’s Metric filters tab, find
IGWChangesFilter. - Click the three dots or the Create alarm link for that metric.
- This takes you to the Specify metric and conditions page:
- Verify Metric namespace:
Security/CloudTrail - Metric:
InternetGatewayChanges
- Verify Metric namespace:
- Under Conditions:
- Statistic:
Sum - Period:
5 minutes(or as desired) - Threshold type:
Static - Whenever metric is:
Greater than - Threshold value:
0
- Statistic:
- Click Next.
Step 3 – Configure Notifications
- 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.
- Choose an existing topic (e.g.,
- Alarm state trigger:
- If you created a new topic:
- After finishing, check your email to Confirm subscription.
- Click Next.
Step 4 – Name and Create the Alarm
- Alarm name:
InternetGatewayChangesAlarm - Alarm description:
Alarm when Create/Delete/Attach/Detach Internet Gateway occurs via CloudTrail - Review all settings.
- Click Create alarm.
Result
Whenever an Internet Gateway is created, deleted, attached, or detached, CloudTrail logs the event, the metric filter incrementsInternetGatewayChanges, and the CloudWatch alarm goes In alarm (and sends SNS notification).Using CLI
Using CLI
Below is a minimal, end‑to‑end example of enabling an “Internet Gateway Changes” CloudWatch alarm using the AWS CLI.Assumptions:
Note the Confirm the subscription from your email.
This creates a metric:
This triggers if at least one IGW change occurs in a 5‑minute period.
- 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.
1. Create (or choose) an SNS topic
TopicArn from the output (call it IGW_TOPIC_ARN).Subscribe your email (or other endpoint):2. Create a CloudWatch Logs metric filter for Internet Gateway changes
Replace:LOG_GROUP_NAMEwith your CloudTrail log group (e.g./aws/cloudtrail/main).
- Namespace:
Security - Name:
InternetGatewayChangesCount - Increments by 1 when any of the above events occurs.
3. Create a CloudWatch alarm on that metric
Replace:REGIONwith your region (e.g.us-east-1).IGW_TOPIC_ARNwith the SNS TopicArn from step 1.
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.
Using Python
Using Python
Below are the steps and example Python (boto3) code to detect and alarm on Internet Gateway changes using AWS CloudWatch:
This setup remediates “Internet Gateway Changes Alarm Should Be Enabled” by programmatically ensuring both the metric filter and the alarm are in place.
1. Prerequisites
-
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
- Install and configure boto3:
2. Decide What to Alert On
We want to monitor CloudTrail events for Internet Gateway changes, e.g.:CreateInternetGatewayDeleteInternetGatewayAttachInternetGatewayDetachInternetGateway
eventName.3. Python Script Overview
The script will:-
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).
-
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_NAMEwith your CloudTrail log group (e.g./aws/cloudtrail/management)YOUR_SNS_TOPIC_ARNwith an SNS topic ARN for notifications- Adjust region/profile as needed.
5. Validation Steps
-
Confirm CloudTrail is logging to the specified log group:
- In the CloudTrail console, open your trail → “CloudWatch Logs” section.
-
Run the script:
-
In the AWS console:
- CloudWatch → Logs → Log groups → select your group → “Metric filters”
ConfirmInternetGatewayChangesFilterexists. - CloudWatch → Alarms
ConfirmInternetGatewayChangesAlarmexists and is inOKstate.
- CloudWatch → Logs → Log groups → select your group → “Metric filters”
-
Test:
- Create or delete an Internet Gateway (or attach/detach it).
- After a few minutes, the alarm should go to
ALARMand 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.
Using Terraform
Using Terraform
LOG_GROUP_NAMEwith your CloudTrail log group name.ARN_OF_SNS_TOPIC_OR_OTHER_ACTIONwith the SNS topic (or other) ARN to notify.
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.
