Ensure a log metric filter and alarm exists for AWS MFA Deletion for IAM users

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for MFA deactivated for IAM users.

Risk Level: Low
Cloud Entity: CloudTrail
CloudGuard Rule ID: D9.AWS.MON.25
Covered by Spectral: Yes
Category: Management Tools


List<CloudTrail> should have items with [hasSNSSubscriber='true' and metricFilters with [filterPattern isFilterPatternEqual('{($.eventName=DeactivateMFADevice)}')]] length() > 0]


From Portal
A. To create a metric filter using the CloudWatch console

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
  2. In the navigation pane, choose Log groups.
  3. Choose the name of the log group.
  4. Choose Actions, Create metric filter.
  5. For Filter pattern, enter the filter pattern to use:
  6. Choose Next, and then enter a name for the filter.
  7. Under Metric details, for Metric namespace, enter a name for the CloudWatch namespace where the metric will be published. If this namespace doesn't already exist, be sure that Create new is selected.
  8. For Metric name, enter a name for the new metric.
  9. For Metric value, if your metric filter is counting occurrences of the keywords in the filter, enter 1.
  10. Choose Create metric filter.

B. Create an SNS topic that the alarm will notify here: https://ap-south-1.console.aws.amazon.com/sns

C. Create an SNS subscription to the topic created in step B here: https://ap-south-1.console.aws.amazon.com/sns

D. Create an alarm that is associated with the CloudWatch Logs Metric Filter created in step A and an SNS topic created in step B here: https://ap-south-1.console.aws.amazon.com/cloudwatch

From TF
To create log metric filter for AWS MFA Deletion for IAM users:

resource "aws_cloudwatch_log_metric_filter" "yada" {
	name           = NAME
	log_group_name = LOG-GROUP-NAME

From Command Line
Perform the following to setup the metric filter, alarm, SNS topic, and subscription:

  1. Create a metric filter based on filter pattern provided which checks for AWS MFA Deletion for IAM users and the LOG-GROUP-NAME
aws logs put-metric-filter --log-group-name LOG-GROUP-NAME --filter-name FILTER-NAME --metric-transformations metricName=METRIC-NAME,metricNamespace=METRIC-NAMESPACE,metricValue=1 --filter-pattern '{($.eventName=DeactivateMFADevice)}'
  1. Create an SNS topic that the alarm will notify:
aws sns create-topic --name SNS-TOPIC-NAME
  1. Create an SNS subscription to the topic created in step 2:
aws sns subscribe --topic-arn SNS-TOPIC-ARN --protocol PROTOCOL --notification-endpoint SNS-ENDPOINT
  1. Create an alarm that is associated with the CloudWatch Logs Metric Filter created in step 1 and an SNS topic created in step 2:
aws cloudwatch put-metric-alarm --alarm-name ALARM-NAME --metric-name METRIC-NAME --statistic Sum --period 300 --threshold 1 --comparison-operator GreaterThanOrEqualToThreshold --evaluation-periods 1 --namespace METRIC-NAMESPACE --alarm-actions SNS-TOPIC-ARN


  1. https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CreateMetricFilterProcedure.html
  2. https://docs.aws.amazon.com/sns/latest/dg/sns-create-topic.html
  3. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ConsoleAlarms.html
  4. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_metric_filter
  5. https://docs.aws.amazon.com/cli/latest/reference/logs/put-metric-filter.html


AWS CloudTrail is a service that enables governance, compliance, operational auditing, and risk auditing of your AWS account. With CloudTrail, you can log, continuously monitor, and retain account activity related to actions across your AWS infrastructure. CloudTrail provides event history of your AWS account activity, including actions taken through the AWS Management Console, AWS SDKs, command line tools, and other AWS services. This event history simplifies security analysis, resource change tracking, and troubleshooting.

Compliance Frameworks

  • AWS CloudGuard Best Practices
  • AWS CloudGuard SOC2 based on AICPA TSC 2017
  • AWS HITRUST v11.0.0
  • AWS ISO27001:2022
  • AWS MITRE ATT&CK Framework v11.3
  • AWS NIST 800-53 Rev 5
  • AWS PCI-DSS 4.0
  • CloudGuard AWS All Rules Ruleset