Analyzing CloudWatch Alarm Service
1. Filter for PutMetricAlarm API Calls
Retrieves detailed information about each PutMetricAlarm API call including the timestamp, alarm name, IAM identity, source IP, and user agent. Useful for auditing who is creating or updating alarms.
SELECT `@timestamp`,
eventName AS API,
`requestParameters.alarmName` AS Alarm_Name,
`userIdentity.arn` AS IAM_Role_User,
sourceIPAddress,
userAgent
FROM `LogGroup`
WHERE eventName = 'PutMetricAlarm'
ORDER BY `@timestamp` DESC
| @timestamp | API | Alarm_Name | IAM_Role_User | sourceIPAddress | userAgent |
|---|---|---|---|---|---|
| 2025-05-19 18:30:45 | PutMetricAlarm | TargetTracking-table/MyTable-AlarmHigh |
arn:aws:sts::123456789012:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling | autoscaling.amazonaws.com | autoscaling.amazonaws.com |
| 2025-05-19 18:30:44 | PutMetricAlarm | TargetTracking-table/MyTable-AlarmLow |
arn:aws:sts::123456789012:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling | autoscaling.amazonaws.com | autoscaling.amazonaws.com |
2. Summarize DescribeAlarms API Calls by IAM Role & Client IP
Counts the number of DescribeAlarms calls made by a specific IAM role, grouped by identity and source IP. Helps identify high-frequency callers for this read operation.
SELECT `userIdentity.arn` AS IAM_Role_User,
sourceIPAddress AS Client_IP,
COUNT(*) AS CallCount
FROM `LogGroup`
WHERE eventName = 'DescribeAlarms'
AND `userIdentity.arn` = 'arn:aws:sts::123456789012:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling'
GROUP BY `userIdentity.arn`, sourceIPAddress
| IAM_Role_User | Client_IP | CallCount |
|---|---|---|
| arn:aws:sts::123456789012:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling | autoscaling.amazonaws.com | 156 |
3. Summarize PutMetricAlarm API Calls by IAM Role & Client IP
Counts the number of PutMetricAlarm calls made by a specific IAM role, grouped by identity and source IP. Useful for understanding how frequently alarms are being created or updated by automated services.
SELECT `userIdentity.arn` AS IAM_Role_User,
sourceIPAddress AS Client_IP,
COUNT(*) AS CallCount
FROM `LogGroup`
WHERE eventName = 'PutMetricAlarm'
AND `userIdentity.arn` = 'arn:aws:sts::123456789012:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling'
GROUP BY `userIdentity.arn`, sourceIPAddress
| IAM_Role_User | Client_IP | CallCount |
|---|---|---|
| arn:aws:sts::123456789012:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling | autoscaling.amazonaws.com | 78 |
4. Summarize PutMetricAlarm API Calls by UserAgent & Namespace
Groups PutMetricAlarm calls by user agent and metric namespace. Reveals which tools or services are creating alarms and for which AWS services.
SELECT userAgent,
`requestParameters.namespace` AS NameSpace,
COUNT(*) AS CallCount
FROM `LogGroup`
WHERE eventName = 'PutMetricAlarm'
GROUP BY userAgent, `requestParameters.namespace`
| userAgent | NameSpace | CallCount |
|---|---|---|
| autoscaling.amazonaws.com | AWS/DynamoDB | 52 |
| APN/1.0 HashiCorp/1.0 Terraform | AWS/EC2 | 18 |
| aws-sdk-go/1.44.0 | AWS/Lambda | 7 |
5. Timeseries: PutMetricAlarm API Calls by Second
Creates a time-series count of PutMetricAlarm calls binned by second. Ideal for visualizing burst patterns or identifying spikes in alarm creation activity.
SELECT COUNT(*) AS CallCount,
bin(1s) AS time_bin
FROM `LogGroup`
WHERE eventName = 'PutMetricAlarm'
GROUP BY bin(1s)
Usage Notes
- Replace
`LogGroup`with the name of your CloudTrail log group in CloudWatch Logs Insights. - These queries target CloudTrail events — ensure CloudTrail is configured to deliver management events to a CloudWatch Logs log group.
- The
bin(1s)function in Query 5 can be adjusted to other intervals (e.g.,bin(1m),bin(5m)) depending on the desired granularity. - Filter on
userIdentity.arnto scope results to a specific IAM role or user when investigating unusual activity. - Use the
ORDER BYandLIMITclauses to manage large result sets and focus on the most recent or highest-count entries.