Missing alarm for network gateway changes

Without a CloudWatch filter and alarm for AWS network gateway changes, changes to the VPC boundary can be discovered late.

Description

Monitor creation and deletion of customer and internet gateways, and attachment or detachment of internet gateways.

Potential impact

A gateway change can interrupt connectivity. Check routes and security groups to see which services are reachable.

Remediation

Send CloudTrail events to CloudWatch Logs. Set the alarm’s metric name and namespace to the filter’s output. Configure the comparison, statistic, period, and evaluation periods. Add an SNS notification action. Use matching test events to reach the alarm threshold and confirm a subscriber receives the alert.

Examples

Here the filter name matches the metric it emits, so the alarm can use the filter’s id as its metric name.

Before

hcl
resource "aws_cloudwatch_metric_alarm" "example" {
  alarm_name  = "CIS-3.12-NetworkGatewayChanges"
  metric_name = "XXXX NOT YOUR FILTER XXXX"
  namespace   = "CIS_Metric_Alarm_Namespace"
  threshold   = "1"
}

After

hcl
resource "aws_cloudwatch_log_metric_filter" "example" {
  name           = "CIS-NetworkGatewayChanges"
  pattern        = "{ ($.eventName = CreateCustomerGateway) || ($.eventName = DeleteCustomerGateway) || ($.eventName = AttachInternetGateway) || ($.eventName = CreateInternetGateway) || ($.eventName = DeleteInternetGateway) || ($.eventName = DetachInternetGateway) }"
  log_group_name = aws_cloudwatch_log_group.CIS_CloudWatch_LogsGroup.name

  metric_transformation {
    name      = "CIS-NetworkGatewayChanges"
    namespace = "CIS_Metric_Alarm_Namespace"
    value     = "1"
  }
}

resource "aws_cloudwatch_metric_alarm" "example" {
  alarm_name  = "CIS-3.12-NetworkGatewayChanges"
  metric_name = aws_cloudwatch_log_metric_filter.example.id
  namespace   = "CIS_Metric_Alarm_Namespace"
  threshold   = "1"
}

References