MongoDB triggers with AWS Eventbridge

If you are a beginner in development then have you ever thought that what will you do if you want to run a service when any change happens in your MongoDB database?

Here what you want is that you want to trigger an event if any changes occur in your database. So to achieve this requirement you will have to use MongoDB triggers along with an AWS service named Eventbridge.

Mongodb Triggers
It allows you to execute a server-side logic whenever either a new document is added or an older document is updated or deleted from the linked MongoDB cluster.

AWS Eventbridge
Amazon EventBridge is a serverless event bus service that makes it easy 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 and routes that data to targets such as AWS Lambda. You can set up routing rules to determine where to send your data to build application architectures that react in real-time to all of your data sources. EventBridge enables you to build event-driven architectures that are loosely coupled and distributed. There are a lot of SaaS providers available and MongoDB is just one of them.

To make a connection, we need to follow some steps on both MongoDB and Eventbridge.

Mongodb atlas 
1. Go to the MongoDB atlas console and select triggers from the left-hand side menu.
2. Click on Add Trigger and this will land you on a page that will show you the options to create the trigger. Then select database trigger as the trigger type and fill rest of the details. When you select your cluster in the link data source section, it will create a realm behind the scene. After that, you will have to select the database and the collection on which you want to execute the server-side logic and what type of operation.
3. In the function section, we need to select Eventbridge and we will be asked to enter our AWS account id and the region in which our account is.
4. Now an optional part will come which is match expression and projection. We will only use it if we would like to be notified in a specific scenario and specific fields. i.e.: We want to be get notified only if the user’s mark is less than 40.
5. Now, Click on save. It will create a new trigger and On the AWS, a new event bus will be created with the same name as of partner event source “aws.partner/mongodb.com/stitch.trigger/{triggerId}” where triggerId is returned from MongoDB.

Now go to the AWS Eventbridge console
1. Click on Partner event sources.
2. Select the record and click on Associate with event bus.
3. Once you click on associate, it will create a new custom bus for you. Click on Event Bus in the left-hand section to verify it under the custom event bus section.
4. Next click on Rules and select the event bus created above from the drop-down and click Create Rule.
5. Select the Pre-defined pattern by service inside the Event matching pattern and select service partners as the service providers and MongoDB as the service name.
6. Select the lambda function as the target and select the lambda function name from the dropdown menu.
7. Click Create.

And you are all done. Congratulation!!!

Latest

SENTRY integration in your React Native App for Error/Crash tracking

Sentry captures data by using an SDK within your...

Recall the concepts of useCallback.

useCallback hook is one of the best hooks offered...

Value of Comments in the code!!

During my journey of Software Development, I am always...

YOLO:Bullet Paced Algorithm

http://sh017.hostgator.tempwebhost.net/media/33949d0e61af4b50f374c534713f56b3 According to world health organization, more than 1.35 million...

Featured

Developing Enterprise Application in Node.js – CJS Vs ESM

Node.js is a popular runtime environment for building server-side...

Integrating your web react applications with their React Native(android and IOS) apps using QR code

Integrating a web application with Android and iOS apps...

YOLO: Bullet Paced Algorithm – popular choice for object detection in autonomous vehicles 

According to world health organization, more than 1.35 million...

Importance of Test Scalar Tool

TestScalar is quick to access, convenient to execute, easy to track. Our popular web-based test planning software lets you focus on what matters: meeting...

From Requirements to Reporting: How to Use a Test Case Management Tool to Ace Your Software Testing

The Software Testing Life Cycle (STLC) is a process that describes the stages of testing software. It includes planning, design, execution, and reporting of...

YOLO:Bullet Paced Algorithm

http://sh017.hostgator.tempwebhost.net/media/33949d0e61af4b50f374c534713f56b3 According to world health organization, more than 1.35 million people die every year because of vehicle accidents . Vehicle safety features started with passive safety...

LEAVE A REPLY

Please enter your comment!
Please enter your name here