Skip to content

Eventbridge rule to email when Config sees new resources

0

I am trying to write an Eventbridge rule that will send a SNS event when Config see a new Instance, LB, ALB and when one is terminated.

I created a rule but its not working. Here is the Template version of that rule.

AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template for EventBridge RuleResourcesAddDeleteInventory
Resources:
  Rule19196363:
    Type: AWS::Events::Rule
    Properties:
      Name: ResourcesAddDeleteInventory
      EventPattern: >-
        {"source":["aws.config"],"detail-type":["Config Configuration Item
        Change"],"detail":{"messageType":["ConfigurationItemChangeNotification"],"configurationItem":{"resourceType":["AWS::EC2::Instance","AWS::ElasticLoadBalancing::LoadBalancer","AWS::ElasticLoadBalancingV2::LoadBalancer","AWS::ElasticLoadBalancingV2::Listener"]}}}
      State: ENABLED
      EventBusName: default
      Targets:
        - Id: Id353b15f8-76a6-4ed5-bf70-490cf675fe6a
          Arn:
            Fn::Sub: >-
              arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:AWSConfigChanges-SNS
Parameters: {}

BTW Config is running in Aggregate mode so it can watch over all my accounts in my Org.

1 Answer
2

Your EventBridge rule is close, but needs some modifications to work as intended:

  1. Adjust the event pattern to specifically capture resource creation and deletion events:

    • Include both "ConfigurationItemChangeNotification" and "OversizedConfigurationItemChangeNotification" in the messageType.
    • Add "ResourceDeleted" and "ResourceDiscovered" to the changeType.
  2. Ensure your SNS topic is properly set up and has the necessary permissions to receive messages from EventBridge.

  3. Consider adding a condition to filter for specific resource states (e.g., "running" for EC2 instances).

Here's an updated version of your CloudFormation template with these changes:

AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template for EventBridge RuleResourcesAddDeleteInventory
Resources:
  Rule19196363:
    Type: AWS::Events::Rule
    Properties:
      Name: ResourcesAddDeleteInventory
      EventPattern:
        source:
          - aws.config
        detail-type:
          - Config Configuration Item Change
        detail:
          messageType:
            - ConfigurationItemChangeNotification
            - OversizedConfigurationItemChangeNotification
          changeType:
            - ResourceDeleted
            - ResourceDiscovered
          configurationItem:
            resourceType:
              - AWS::EC2::Instance
              - AWS::ElasticLoadBalancing::LoadBalancer
              - AWS::ElasticLoadBalancingV2::LoadBalancer
              - AWS::ElasticLoadBalancingV2::Listener
      State: ENABLED
      EventBusName: default
      Targets:
        - Id: Id353b15f8-76a6-4ed5-bf70-490cf675fe6a
          Arn:
            Fn::Sub: arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:AWSConfigChanges-SNS

Parameters: {}

Make sure your AWS Config is set up correctly to record all supported resource types, including the ones you're interested in. Also, verify that your SNS topic (AWSConfigChanges-SNS) exists and has the proper access policy to allow EventBridge to publish messages to it.

If you're using AWS Config in aggregator mode to watch over all accounts in your organization, ensure that the aggregator is properly set up and that the necessary permissions are in place for cross-account access.

After making these changes, deploy the updated CloudFormation template. This should create an EventBridge rule that triggers SNS notifications when the specified resources are created or deleted across your AWS accounts.

Sources
Monitoring AWS Config with Amazon EventBridge - AWS Config
Configuring an EventBridge rule to send notifications about events in AWS Health - AWS Health

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.