DEV Community

Ariel Coba
Ariel Coba

Posted on

Send Event Notifications from MongoDB Trigger to AWS Eventbridge

Introduction

What if you want to record any action performed in your database and send an SMS notification to your Smart device? You'll see this great approach that I've performed just for fun :).

MongoDB Side

Create MongoDB Trigger

Go to your MongoDB Atlas Cluster and Add a new Trigger

MongoDBAddTrigger

Select Database as Trigger Type, enter a name for your trigger and link a data source to itP:

MongoDBTrigger01

Select your Cluster, Database, Collection Names and the operations you want to fire up the trigger:

MongoDBTrigger02

Select EventBridge as Event Type, Enter your AWS Account ID and Region:

MongoDBTrigger03

AWS Side

Let's go to Amazon EventBridge>Partner event sources and you'll see the Event Source added after creating the trigger within MongoDB, now we have to associate this event

EventBridge001

You can use the default options while associating this event source:

EventBridge002

You'll see the event in Active state after this process:

EventBridge007

Now, let's go to Rules, Select the Event Bus already created from the drown dop list and create a rule:

EventBridge008

Let's put a name to this rule and use the default options in section 1:

EventBridge009

Go to Event Pattern in Section 2 and select the options from the image below:

EventBridge010

In section 3, use AWS Service as target type, in target you can use any option you want but, in this example, I'll be using SNS Topic:

EventBridge011

Open a new tab from your browser for your AWS Console and got to SNS (Simple Notification Service):

SNS001

Enter a display for this SNS and leave the other options as default:

SNS002

Now, let's create a subscription:

SNS003

Select your topic ARN already created SMS as protocol and select your phone number from the list.

SNS004

After selecting your target and SNS Topic, you can click on Next and Create your Rule:

EventBridge012

After creating your rule, we can go back to our MongoDB Atlas Cluster and perform a test by removing a document:

MongoDB001

I've got my notification via SMS that a document was deleted, this is working!

SMS

I hope you find this information helpful, if you have any issues, comments or feedback shoot me a comment.

Have a good one community!

Top comments (0)