Amazon Kinesis Data Firehose now supports the MongoDB Cloud platform as one of its delivery destinations. This native integration between Kinesis Data Firehose and MongoDB Cloud provides a managed, secure, scalable, and fault-tolerant delivery mechanism for customers into MongoDB Atlas, a global cloud solution for fully managed MongoDB database service for modern applications.
With the release of Kinesis Data Firehose HTTP endpoint delivery, you can now stream your data through Amazon Data Streams or directly push data to Kinesis Data Firehose and configure it to deliver data to MongoDB Atlas. You can also configure Kinesis Data Firehose to transform the data before delivering it to its destination. You don’t have to write applications and manage resources to read data and push to MongoDB. It’s all managed by AWS, making it easier to estimate costs for your data based on your data volume.
In this post, we discuss how to integrate Kinesis Data Firehose and MongoDB Cloud and demonstrate how to stream data from your source to MongoDB Atlas.
Integrating Kinesis Data Firehose and MongoDB Atlas
Kinesis Data Firehose is a fully managed service that automatically scales to match the throughput of your data and requires no ongoing administration. It can also batch, compress, transform, and encrypt the data before loading it, which minimizes the amount of storage used at the destination and increases security.
As part of Kinesis Data Firehose, you can transform your records before delivering them to the destination. In addition, Kinesis Data Firehose enables you to buffer data (based on size or time) before delivering to the final destination. In case of delivery failures, Kinesis Data Firehose can store your failed records in an Amazon Simple Storage Service (Amazon S3) bucket to prevent data loss.
MongoDB Atlas is a platform that can be used across a range of Online Transactional Processing (OLTP) and data analytics applications. MongoDB Atlas allows developers to address popular use cases such as Internet of Things (IoT), Mobile Apps, Payments, Single View, Customer Data Management and many more. In all of those cases, developers spend significant amount of time on delivering data to MongoDB Atlas from various data sources. This integration significantly reduces the amount of development effort by leveraging Kinesis Data Firehose HTTP Endpoint integration to ingest data into MongoDB Atlas.
Creating a MongoDB Cloud Realm Application
- Log into your MongoDB cloud account. If you do not have an account you can sign up for a free account.
- Create an HTTP endpoint on the MongoDB Atlas platform by choosing 3rd Party Services on the Realm tab.
- Choose Add a Service.
- Choose HTTP.
- For Service Name, enter a name. Your service will appear under this name on the UI.
- Choose Add Incoming Webhook.
- For Authentication, select System.
- Leave other options at their default.
- In the function editor, enter the following code:
The preceding code is a simplified implementation of the webhook. The webhook inserts records one at a time and has abbreviated for readability error handling. For more information about the full implementation, see Using MongoDB Realm WebHooks with Amazon Kinesis Data Firehose.
This webhook uses the values and secrets of MongoDB Realm.
- On the Realm tab, choose Values & Secrets.
- On the Secrets tab, choose Create New Secret/Add a Secret.
- Enter the Secret Name and Secret Value and click save. The Secret Name entered here is the name used in webhook code.
- On the Values tab, choose Create New Value/dd a Value.
- Enter the Value Name.
- For Value Type, select Secret.
- For Secret Name, choose the secret you created.
- Choose Save.
You can now use the secret in your webhook function.
- Choose REVIEW & DEPLOY.
Creating a Kinesis Data Firehose delivery stream to MongoDB
- Log into AWS Console and search for Kinesis.
- On the Kinesis Data Firehose console, choose Create delivery stream.
- For Delivery stream name, enter a name.
- For Source, choose Direct PUT of other sources.
- Choose Next.
- On the Process recordspage, keep all settings at their default and choose Next.
- From the Third-party partner drop-down menu, choose MongoDB Cloud.
- For MongoDB Realm Webhooks HTTP Endpoint URL, please enter the URL of realm app that was created in MongoDB cloud console.
- For API Key, please enter the secret value stored in MongoDB secrets section.
- For Content encoding, leave it as Disabled.
- For S3 backup mode, select Failed data only.
- For S3 bucket, enter the S3 bucket for delivery of log events that exceeded the retry duration. Alternatively, you can create a new bucket by choosing Create new.
- Click on Next.
- For MongoDB buffer conditions, accept the default MongoDB and Amazon S3 buffer conditions for your stream. Note that the buffer size should be a value between 1MiB and 16MiB. Review the limits in MongoDB Atlas documentation.
- In the IAM role section, configure permissions for your delivery stream by choosing Create or update IAM role.
- Choose Next.
- Review your settings and choose Create delivery stream.
As part of HTTP endpoint integration, Kinesis Data Firehose only supports HTTPS endpoints. The server-side TLS/SSL certificate must be signed by a trusted Certificate Authority (CA) and is used for verification by Kinesis Data Firehose.
The body of the request that is delivered from Kinesis Data Firehose is a JSON document with the following schema:
The records are delivered as a collection based on
BufferingHints configured on the Firehose delivery stream. The delivery-side service webhook created on MongoDB Realm has to process these records one by one before inserting them into MongoDB collections or use the MongoDB Bulk APIs.
When Kinesis Data Firehose is set up with an HTTP endpoint destination to MongoDB Cloud, you can push data into Kinesis Data Firehose using Kinesis Agent or SDK from your application. Kinesis Data Firehose is also integrated with other AWS data sources such as Kinesis Data Streams, AWS IoT, Amazon CloudWatch Logs, and Amazon CloudWatch Events.
To test the integration, use the testing option on the Kinesis Data Firehose console and test with sample data. After the time configured in
BufferingHints, log in to your Atlas platform and navigate to your Database/Collection to see the ingested records.
In this post, we showed how easy it is to ingest data into the MongoDB Cloud platform using a Kinesis Data Firehose HTTP endpoint. This integration has many use cases. For example you can stream Internet of Things (IoT) data directly into MongoDB Atlas platform with minimum code using AWS Kinesis Data Firehose HTTP endpoint integration. Try MongoDB Atlas on AWS here.
About the Author
Anusha Dharmalingam is a Solutions Architect at Amazon Web Services, with a passion for Application Development and Big Data solutions. Anusha works with enterprise customers to help them architect, build, and scale applications to achieve their business goals.
Igor Alekseev is a Partner Solution Architect at AWS in Data and Analytics. Igor works with strategic partners helping them build complex, AWS-optimized architectures. Prior joining AWS, as a Data/Solution Architect, he implemented many projects in Big Data, including several data lakes in the Hadoop ecosystem. As a Data Engineer, he was involved in applying AI/ML to fraud detection and office automation. Igor’s projects were in a variety of industries including communications, finance, public safety, manufacturing, and healthcare. Earlier, Igor worked as full stack engineer/tech lead.
Credit: Source link