Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

mongodb-developer/EventbridgeAtlas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 

Repository files navigation

Notice: Repository Deprecation

This repository is deprecated and no longer actively maintained. It contains outdated code examples or practices that do not align with current MongoDB best practices. While the repository remains accessible for reference purposes, we strongly discourage its use in production environments. Users should be aware that this repository will not receive any further updates, bug fixes, or security patches. This code may expose you to security vulnerabilities, compatibility issues with current MongoDB versions, and potential performance problems. Any implementation based on this repository is at the user's own risk. For up-to-date resources, please refer to the MongoDB Developer Center.

EventBridgeAtlas

This demonstrates how Realm HTTPS Endpoints can be invoked to perform CRUD operations on collections residing in MongoDB Atlas from the EventBridge API Endpoints option.

Architectural Overview

Architecture

Prerequisites and Setup

Create a Cluster on MongoDB Atlas

  • Follow the steps here to create a new database cluster
  • Configure database user, IP Whitelist and copy the connection string. Follow the steps here

Create Realm Webhook

Before we can write the code for our webhook, we first need to configure it. The Configure Service HTTPS Endpoints guide in the Realm documentation goes into more detail, but you will need to configure the following options:

*Authentication type must be set to system *The HTTP method is POST *Keep rest of the parameters deafult. ConfigureWebhook

Create Realm Function

For our Webhook we need to write a function which:

  • Receives a POST request from EventBridge
  • Parses the JSON body from the request
  • Iterates over the array
  • Writes the object to MongoDB Atlas as a new document
  • Returns the correct status code and JSON body to EventBridge in the response

https://github.com/mongodb-developer/EventbridgeAtlas/blob/main/InsertFunction.js does these steps. Copy this into Realm functions logic placeholder as shown in the below screenshot.

CreateFunction

Test the Webhook

Copy the webhook URL in settings. Also copy sample curl command snapshot below:

WebhookURL

Execute with below JSON Array in the body: [{"field":"value1"},{"field":"value2"}] Eg: curl
-H "Content-Type: application/json"
-d '[{"field":"value1"},{"field":"value2"}]'
https://webhooks.mongodb-realm.com/api/client/v2.0/app/application-0-rosmq/service/test/incoming_webhook/webhook0

Test whether the data is getting added in the collection.

Integrate this with EventBridge

  1. Select the target to invoke when an event matches your event pattern or when schedule is triggered. In this case target would be API Destination. selectTarget

  2. Select Create a new API Destination. newAPIDestination

  3. Configure API Destination Details with details of the webhook you already created in the previous step. EventBridge supports Basic, OAuth and API Key Authorizations configureAPIDestination

  4. You can add invocation HTTP parameters. configureParameters

  5. Name your connection. You will be able select a connection when you create an API destination. defineConnection

  6. Save and start pushing the data. You shoule be able to see it being uploaded in your Atlas cluster. dataPopulated

About

https://github.com/pareshsaraf/EventbridgeAtlas. Please make sure I can still edit as we still need to make a few changes: https://github.com/danared

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •