DEV Community

GargeeBhatnagar for AWS Community Builders

Posted on

Deployment of Customized EventBridge Rules Using Serverless Application Model and CloudFormation Template from CodePipeline

“ I have checked the documents of AWS to deploy customized eventbridge rules using SAM and Cloudformation template . Issue in creation of template as per requirement but after giving parameters in different ways and IAM permissions the problem is resolved . In terms of cost, the solution is cheaper and secure.”

Amazon EventBridge is a serverless event bus service that you can use to connect your applications with data from a variety of sources. EventBridge delivers a stream of real-time data from your applications, software as a service (SaaS) applications, and AWS services to targets such as AWS Lambda functions, HTTP invocation endpoints using API destinations, or event buses in other AWS accounts.

A rule matches incoming events and sends them to targets for processing. A single rule can send an event to multiple targets, which then run in parallel. Rules are based either on an event pattern or a schedule. An event pattern defines the event structure and the fields that a rule matches. Rules that are based on a schedule perform an action at regular intervals.

In this post, you will experience the deployment of customized eventbridge rules using serverless application model and cloudformation template from codepipeline. Here I have created a s3, kms, codecommit repo and codepipeline for deployment of eventbridge rules which is created using sam and cloudformation template parameters. Also created lambda and step function for target purpose.

Prerequisites

You’ll need an AWS Step Functions for this post. Getting started with AWS Step Functions provides instructions on how to create a step function with multiple service inputs for flow perspective.

You’ll need an AWS Lambda for this post. Getting started with aws Lambda provides instructions on how to create a lambda function. For this blog, I assume that I have a lambda function and a step function.

Architecture Overview

Image description
The architecture diagram shows the overall deployment architecture with data flow, two aws account, code commit, code build, code deploy, code pipeline, s3, cloudformation, artifact, lambda, kms, step function and eventbridge rule.

Solution overview

The blog post consists of the following phases:

  1. In Account A, Create of S3, KMS, IAM, CodeCommit Repo and CodePipeline
  2. In Account A, Create of BuildSpec.yml and Template.yaml File Which Contains Configuration Details for EventBridge Rules Using Serverless Application Model Template and Cloudformation Template Parameters
  3. In Account B, Creation of EventBridge Rules via Cloudformation Stack from Pipeline of Account A and its ChangeSet Parameter

In Account B, I have a lambda function and a step function created as below →
Image description
Image description

Phase 1: In Account A, Create of S3, KMS, IAM, CodeCommit Repo and CodePipeline

  1. Open the console for S3, KMS, IAM, CodeCommit Repo and CodePipeline manually or using cloudformation stack. Image description Image description Image description Image description Image description

Phase 2: In Account A, Create of BuildSpec.yml and Template.yaml File Which Contains Configuration Details for EventBridge Rules Using Serverless Application Model Template and Cloudformation Template Parameters

  1. Open the CodeCommit console, Create a buildspec file and template file. Template file contains customized parameters for creating event bridge rules of s3 as source and step function as target where lambda invoke in step function. Image description Image description Image description Image description Image description

Phase 3: In Account B, Creation of EventBridge Rules via Cloudformation Stack from Pipeline of Account A and its ChangeSet Parameter

  1. Once the changes deploy in the main branch of repo, the pipeline gets triggered and creates the eventbridge rules for step function as a target with lambda invoke. Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description Image description

Clean-up

In Account B: Delete of cloudformation stack, IAM, lambda and step function. In Account A: Delete of S3, KMS, IAM, codecommit repo and codepipeline.

Pricing

I review the pricing and estimated cost of this example.

Cost of CodeBuild = $0.0

Cost of CodeCommit = $0.0

Cost of Lambda = $0.0

Cost of Key Management Service = $0.01

Cost of Simple Storage Service = $1.0

Cost of Step Functions = $0.0

Cost of EventBridge Rules = $0.0

Total Cost = $(0.0 + 0.0 + 0.0 + 0.01 + 1.0 + 0.0 + 0.0) = $1.01

Summary

In this post, I showed “how to deploy customized eventbridge rules using serverless application model and cloudformation template from codepipeline”.

For more details on Amazon EventBridge Rules, Checkout Get started Amazon EventBridge Rules, open the Amazon EventBridge console. To learn more, read the Amazon EventBridge documentation.

Thanks for reading!

Connect with me: Linkedin
Image description

Oldest comments (0)