How to monitoring Cloudformation events in Amazon EventBridge / Amazon CloudWatch?

Viewed 2746

How to monitoring Cloudformation events in Amazon EventBridge / Amazon CloudWatch?

My approach is to trigger a lambda event based as soon as a specific Cloudformation stack is created successfully.

Therefor i like to declare an event rule - but the source and event details are not clear to me?

  CreatePipelineRule:
    Type: AWS::Events::Rule
    Properties: 
      Description: "EventRule"
      EventPattern:
        source:
          - aws.???
        detail-type:
          - 'Cloudformation stack created event'
        detail:
          event:
              - ???          
      State: ENABLED

Unfortunately i can not find a documentation related to this events. In General the event pattern is described https://docs.aws.amazon.com/eventbridge/latest/userguide/filtering-examples-structure.html

For some sources like code commit the generated events are well documented. For example code commit: https://docs.aws.amazon.com/codecommit/latest/userguide/monitoring-events.html.

Is there also a list of events generated by Cloudformation?

1 Answers

I couldn't find any documentation myself, so to see what kind of events CloudFormation sends, I temporarily created a new event rule in EventBridge:

  • chose Pre-defined pattern by service and selected CloudFormation from the service list
  • chose CloudWatch log group as target to get all the events printed to CloudWatch

For example when you create a new stack, you receive two events where the source is aws.cloudformation and the details include one of the following:

  • "eventName": "EstimateTemplateCost"
  • "eventName": "CreateStack"

Or when you delete a stack you get:

  • "eventName": "DeleteStack"

The issue is that CloudFormation only sends events when you start an operation, but not when it finishes (neither when it succeeds, nor when it rolls back). Therefore, using an event rule might not be the way to trigger a Lambda upon stack creation. I recommend looking into Custom Resources instead. Include one into your CloudFormation template to target your Lambda function and use DependsOn tags to make sure it only runs when everything else was deployed successfully.

Related