More Info:
AWS security groups 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)
- 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
- 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-based steps to set up a CloudWatch alarm for Security Group changes using CloudTrail logs.
1. Ensure CloudTrail Is Enabled and Sending Logs to CloudWatch Logs
- In the AWS Management Console, go to CloudTrail.
- In the left pane, choose Trails.
- Either:
- Use existing trail that already:
- Logs Management events (Read/Write or at least Write-only).
- Delivers logs to a CloudWatch Logs log group,
- Or create/configure one:
- Click Create trail (or select a trail → Edit).
- Under Management events, ensure Write is enabled.
- Under CloudWatch Logs, choose Enabled.
- Select or create:
- A CloudWatch log group, and
- An IAM role for CloudTrail to put logs in CloudWatch Logs.
- Save the trail.
- Use existing trail that already:
2. Create a Metric Filter for Security Group Changes
- Go to CloudWatch in the console.
- In the left pane, select Logs → Log groups.
-
Click the log group that CloudTrail is configured to use (e.g.,
/aws/cloudtrail/logs). - Select the Metric filters tab.
- Click Create metric filter.
-
Under Filter pattern, paste:
- Click Next.
-
For Metric name, enter something like:
SecurityGroupChangeCount. -
For Metric namespace, use something like:
CIS/SecurityGroup. -
For Metric value, enter:
1. -
Leave Default value empty or
0(optional). - Click Next, then Create metric filter.
3. Create a CloudWatch Alarm for the Metric
- Still in CloudWatch, go to Alarms → All alarms.
- Click Create alarm.
- Click Select metric.
- Navigate to the namespace you created: CIS → SecurityGroup → Metrics with no dimensions (or whatever you named it).
- Select the metric SecurityGroupChangeCount and click Next.
4. Configure Alarm Threshold
- Under Conditions:
- Statistic:
Sum. - Period: e.g.,
5 minutes. - Threshold type:
Static. - Whenever SecurityGroupChangeCount is:
>= 1.
- Statistic:
- Click Next.
5. Set Notification (SNS) for the Alarm
- Under Notification:
- Alarm state trigger:
In alarm. - Select an SNS topic (e.g.,
security-alerts), or click Create new topic:- Give it a name, e.g.,
security-group-changes-topic. - Add your email address (or other endpoints) as a subscription.
- Give it a name, e.g.,
- Alarm state trigger:
- Click Next.
6. Name and Create the Alarm
- Give the alarm a name like:
SecurityGroupChangesAlarm. - (Optional) Add a description, e.g., “Alarm on any Security Group change events from CloudTrail”.
- Review settings and click Create alarm.
7. Confirm SNS Subscription
- Check your email (or other endpoint) for the SNS subscription confirmation message.
- Confirm the subscription so you receive alerts.
Using CLI
Using CLI
Below is one straightforward way to do this entirely via AWS CLI using a CloudWatch Logs metric filter on CloudTrail logs, plus a CloudWatch alarm.Assumptions (adjust as needed):
If
This creates a metric that increments whenever a security group is created, deleted, or its rules are changed.
This alarm will go into ALARM state (and notify via SNS) if at least one security group change event is logged in the last 5 minutes.
Within a few minutes, the metric should increment and the alarm should trigger.
- You already have a CloudTrail trail that logs to a CloudWatch Logs log group.
- Log group name:
CloudTrail/DefaultLogGroup - Region:
us-east-1 - SNS topic for notifications:
arn:aws:sns:us-east-1:123456789012:SecurityNotifications
1. Verify your CloudTrail is sending logs to CloudWatch Logs
CloudWatchLogsLogGroupArn is empty, you must configure CloudTrail to send to a log group first (either via console or update-trail + put-event-selectors). Once CloudTrail is delivering events to a log group, use that log group name in the steps below.2. Create the CloudWatch Logs metric filter
Replace the log group name as needed.3. Create the CloudWatch alarm on that metric
4. (Optional) Test the setup
Perform an action like adding a rule to a security group:Using Python
Using Python
Below are the steps and sample Python (boto3) code to enable an alarm on Security Group changes using CloudWatch in AWS.
You must have an IAM role (
Python to create the metric filter:This will emit a metric value of
If you share your exact account/region/log group names and whether CloudTrail → CloudWatch Logs is already configured, I can adapt the code snippets precisely to your environment.
Overview
To alarm on Security Group changes, you typically:- Ensure CloudTrail is logging management events for EC2 (Security Groups) and sending logs to CloudWatch Logs.
- Create a CloudWatch Logs metric filter on those CloudTrail events.
- Create a CloudWatch alarm on that metric.
1. Prerequisites
boto3installed:- AWS credentials configured (via environment vars,
~/.aws/credentials, or IAM role). - An existing CloudTrail that:
- Logs management events.
- Delivers to a CloudWatch Logs log group (you need that log group name).
- Region:
us-east-1 - CloudWatch Logs group:
/aws/cloudtrail/security - Metric namespace:
SecurityGroupMonitoring - Metric name:
SecurityGroupChanges - Alarm name:
SecurityGroupChangesAlarm - Notification via SNS topic ARN:
arn:aws:sns:us-east-1:123456789012:secgroup-alerts
2. Ensure CloudTrail is Sending to CloudWatch Logs (Python)
If you already have this set up, you can skip this step.CloudTrail_CloudWatchLogs_Role) with the appropriate trust policy for CloudTrail and permissions to write to the log group.3. Create CloudWatch Logs Metric Filter for Security Group Changes
Target CloudTrail events for Security Groups, e.g.:AuthorizeSecurityGroupIngressAuthorizeSecurityGroupEgressRevokeSecurityGroupIngressRevokeSecurityGroupEgressCreateSecurityGroupDeleteSecurityGroupUpdateSecurityGroupRuleDescriptionsIngressUpdateSecurityGroupRuleDescriptionsEgress
1 every time a matching event occurs.4. Create a CloudWatch Alarm on That Metric
For example, trigger an alarm if ≥ 1 change occurs in a 5‑minute period.5. Validation
- Make a small SG change (e.g., add/remove a rule).
- Wait a few minutes.
- In CloudWatch console:
- Check the custom metric
SecurityGroupMonitoring / SecurityGroupChanges. - Confirm it registers data points.
- Confirm
SecurityGroupChangesAlarmchanges state toALARMand SNS is triggered.
- Check the custom metric
If you share your exact account/region/log group names and whether CloudTrail → CloudWatch Logs is already configured, I can adapt the code snippets precisely to your environment.
Using Terraform
Using Terraform
terraform plan should show 4 resources to add: aws_cloudwatch_log_metric_filter.security_group_changes, aws_sns_topic.security_group_changes, aws_sns_topic_subscription.security_group_changes_email, and aws_cloudwatch_metric_alarm.security_group_changes, with no changes to other resources.
