MongoDB Developer
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right

Get Started with MongoDB Atlas and AWS CloudFormation

Jason MimickPublished Jan 14, 2022 • Updated Sep 23, 2022
Facebook Icontwitter iconlinkedin icon
Rate this code example
social-githubView Code
It's pretty amazing that we can now deploy and control massive systems in the cloud from our laptops and phones. And it's so easy to take for granted when it all works, but not so awesome when everything is broken after coming back on Monday morning after a long weekend! On top of that, the tooling that's available is constantly changing and updating and soon you are drowning in dependabot PRs.
The reality of setting up and configuring all the tools necessary to deploy an app is time-consuming, error-prone, and can result in security risks if you're not careful. These are just a few of the reasons we've all witnessed the incredible growth of DevOps tooling as we continue the evolution to and in the cloud.
AWS CloudFormation is an infrastructure-as-code (IaC) service that helps you model and set up your Amazon Web Services resources so that you can spend less time managing those resources and more time focusing on your applications that run in AWS. CloudFormation, or CFN, let's users create and manage AWS resources directly from templates which provide dependable out of the box blueprint deployments for any kind of cloud app.
To better serve customers using modern cloud-native workflows, MongoDB Atlas supports native CFN templates with a new set of Resource Types. This new integration allows you to manage complete MongoDB Atlas deployments through the AWS CloudFormation console and CLI so your apps can securely consume data services with full AWS cloud ecosystem support.

Launch a MongoDB Atlas Stack on AWS CloudFormation

We created a helper project that walks you through an end-to-end example of setting up and launching a MongoDB Atlas stack in AWS CloudFormation.
The get-started-aws-cfn project builds out a complete MongoDB Atlas deployment, which includes a MongoDB Atlas project, cluster, AWS IAM role-type database user, and IP access list entry.
You can also use the AWS Quick Start for MongoDB Atlas that uses the same resources for CloudFormation and includes network peering to a new or existing VPC.
Deploy MongoDB Atlas using AWS CloudFormation
You're most likely already set up to run the get-started-aws-cfn since the project uses common tools like the AWS CLI and Docker, but just in case, head over to the prerequisites section to check your development machine. (If you haven't already, you'll want to create a MongoDB Atlas account.)
The project has two main parts: "get-setup' will deploy and configure the MongoDB Atlas CloudFormation resources into the AWS region of your choice, while "get-started' will launch your complete Atlas deployment.

Step 1) Get Set Up

Clone the get-started-aws-cfn repo and get setup:

Step 2) Get Started

Run the get-started script:
Launch a MongoDB Atlas deployment with the AWS CLI using CloudFormation with the Get Started project
Once the stack is launched, you will start to see resources getting created in the AWS CloudFormation console. The Atlas cluster takes a few minutes to spin up completely, and you can track the progress in the console or through the AWS CLI.
View and manage MongoDB Atlas resources from the AWS CloudFormation console.

Step 3) Get Connected

Once your MongoDB Atlas cluster is deployed successfully, you can find its connection string under the Outputs tab as the value for the "ClusterSrvAddress' key.
Use the ClusterSrvAddress output in AWS CloudFormation to connect to your MongoDB Atlas cluster.
The Get-Started project also has a helper script to combine the AWS and MongoDB shells to securely connect via an AWS IAM role session. Check out connecting to your cluster for more information.
What next? You can connect to your MongoDB Atlas cluster from the mongo shell, MongoDB Compass, or any of our supported drivers. We have guides for those using Atlas with popular languages: Here's one for how to connect to Atlas with Node.js and another for getting started with Java.


Use the MongoDB Atlas CloudFormation Resources to power everything from the most basic "hello-world' apps to the most advanced devops pipelines. Jump start your new projects today with the MongoDB Atlas AWS CloudFormation Get-Started project!
If you have questions, please head to our developer community website where the MongoDB engineers and the MongoDB community will help you build your next big idea with MongoDB.

Facebook Icontwitter iconlinkedin icon
Rate this code example

Local Development with the MongoDB Atlas CLI and Docker

Feb 06, 2023
Code Example

Build Your Own Wordle in Bash with the Data API

Aug 26, 2022

Procedure to Allow Non-Root Users to Stop/Start/Restart "mongod" Process

May 16, 2022

Designing, Developing, and Analyzing with the New MongoDB Shell

Feb 03, 2023
Technologies Used
Table of Contents