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
Select Database as Trigger Type, enter a name for your trigger and link a data source to itP:
Select your Cluster, Database, Collection Names and the operations you want to fire up the trigger:
Select EventBridge as Event Type, Enter your AWS Account ID and Region:
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
You can use the default options while associating this event source:
You'll see the event in Active state after this process:
Now, let's go to Rules, Select the Event Bus already created from the drown dop list and create a rule:
Let's put a name to this rule and use the default options in section 1:
Go to Event Pattern in Section 2 and select the options from the image below:
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:
Open a new tab from your browser for your AWS Console and got to SNS (Simple Notification Service):
Enter a display for this SNS and leave the other options as default:
Now, let's create a subscription:
Select your topic ARN already created SMS as protocol and select your phone number from the list.
After selecting your target and SNS Topic, you can click on Next and Create your Rule:
After creating your rule, we can go back to our MongoDB Atlas Cluster and perform a test by removing a document:
I've got my notification via SMS that a document was deleted, this is working!
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)