AWS Partner Network (APN) Blog
Application Modernization with AWS Elastic Beanstalk and MongoDB Atlas
By Igor Alekseev, Partner Solutions Architect, Data and Analytics – AWS
By Babu Srinivasan, Sr. Solutions Architect – MongoDB
By Utsav Talwar, Associate Partner Solutions Architect – MongoDB
Digital transformation is a must in order to keep businesses competitive in the current economic landscape. To meet the changing needs of customers, enterprises have to be agile—a difficult goal especially in the presence of legacy monolithic architectures and the resulting technical debt.
One secret to success is to focus on building new applications to make a difference, rather than fighting out how to cope with changes in the old system.
This post guides you to make application modernization easier with AWS Elastic Beanstalk and MongoDB Atlas. MongoDB is an AWS Data and Analytics Competency Partner and developer data platform company empowering innovators to create, transform, and disrupt industries by unleashing the power of software and data.
MongoDB Atlas gives developers the ability to build modern applications that are highly available, performant on a global scale, and compliant with the most demanding security and privacy standards.
Using MongoDB Atlas on Amazon Web Service (AWS), developers can focus on driving innovation and business value instead of managing infrastructure. Developers can also use services like Atlas Search, Atlas App Services, and Atlas Data Lake, making MongoDB Atlas a comprehensive data platform for developers.
AWS Elastic Beanstalk makes it easier for developers to quickly deploy and manage their applications on AWS. Developers can upload their code, and Elastic Beanstalk automatically handles the deployment details of auto scaling, capacity provisioning, load balancing, and application health monitoring.
MongoDB Atlas + AWS Elastic Beanstalk
As a developer data platform, MongoDB facilitates the application development process by simplifying database management tasks like schema modeling, automating key logistics, and providing an intuitive user experience. MongoDB also supports multiple languages like C, C++, C#, Go, Java, Node.js, PHP, and Python.
The MEAN or MERN stack application can be developed, containerized, and deployed using AWS Elastic Beanstalk, which provides an environment for web applications that handles resource provisioning, maintenance, health checks, automatic scaling, and other common tasks necessary to keep the application running. This allows developers to focus on application code.
Using Elastic Beanstalk and MongoDB, developers can modernize legacy infrastructure, transitioning them from outdated three-tier architectures to cloud-based applications.
Legacy and Monolithic Architecture
The illustration below shows a range of modernization processes for legacy and monolithic architectures, including microservices, serverless, containerization, and cloud-native solutions.
Figure 1 – Legacy and monolithic architecture.
This figure shows how in traditional three-tier architectures, developers decompose application into separate tiers. The tiers are usually tightly coupled together, making it hard to add new functionality and resulting in a less agile process.
An important part of an agile development process is the blue-green application release model, which requires a database that is schema flexible. With a three-tier application, the traditional approach involves downtime with database schema updates and data migration procedure. These are usually stateful architectures requiring significant effort to manage state impeding scalability, and it’s hard to decompose a three-tier application beyond the three tiers.
This becomes a problem when there’s need to scale only a part of the application. Because of interdependency, the workload cannot be isolated and requires refactoring of the whole tier, typically the middle tier.
A popular methodology is to do API-first development. This naturally fits into microservices architectures where some APIs can evolve independently. It also leads to the need for well-architected modern microservices-based applications.
Modern architectures are stateless, serverless, containerized, and have well-defined APIs. They are often cloud-native and take advantage of the cloud’s elasticity. There is usually an API gateway, microservices-based compute, and aa scalable document-based database like MongoDB Atlas.
Figure 2 – AWS Elastic Beanstalk with Atlas architecture.
The figure above shows a MEAN-based application deployed to AWS Elastic Beanstalk with MongoDB Atlas serving as the application backend and AWS PrivateLink keeping the network traffic to the cluster private.
The application has two separate modules: frontend and backend. Additional modules can be added following the principles of the modern architectures described above. These new modules can connect to the existing MongoDB cluster, or an additional cluster can be provisioned following database-per-service pattern. For example, if a module is used infrequently you can create a separate serverless MongoDB Atlas instance to take advantage of its elasticity for the periods when the module is inactive.
In the following steps, you will deploy an application using the MEAN stack (with MongoDB Atlas as the backend database). The steps are identical for MERN stack.
You can bring your own application or use the sample application provided. You will containerize the application code using Docker tooling, and you will create and deploy the application container to the AWS Elastic Beanstalk environment using its command line interface (CLI).
Finally, you’ll test the application via an endpoint created by Elastic Beanstalk and exposed through the Application Load Balancer.
To get started, first make sure you have set up a MongoDB Atlas cluster and configured access and network as described in Step 1 of this GitHub repository. If you’re using an existing cluster, you can skip this step.
Next, follow the instructions in Step 2 to configure the Elastic Beanstalk CLI which you are using to interact with the services. In Step 3, you’re initializing the environment and deploying the application.
As part of application configuration, you can supply a serverless MongoDB Atlas instance connection string. Doing so adds serverless capabilities to the application. Now the database can expand and contract based on the usage.
Once the environment deployment grows through, a message similar to the one below confirms successful deployment of the environment:
If application deployment goes successfully, you should get a green check mark on the application health status user interface (UI).
Figure 3 – Elastic Beanstalk health UI.
The figure above shows your application when it’s in healthy state. Now you can try the application in a browser.
Figure 4 – Web application UI.
The figure above shows the sample application web UI with several records created and saved to MongoDB Atlas.
Use the Elastic Beanstalk Logs section to troubleshoot application deployment. If you need to make changes to the application, use the
eb deploy command to redeploy your changes.
Figure 5 – Elastic Beanstalk Logs UI.
The figure above shows how to retrieve the logs for your Elastic Beanstalk application.
With very few commands, you have deployed a web application consisting of two separate modules. The application is backed by a serverless database, MongoDB Atlas Serverless.
By leveraging AWS Elastic Beanstalk with MongoDB Atlas, you can develop applications rapidly and deploy easily on the AWS Cloud.
This streamlined application modernization process, resulting in more secure and scalable applications, allows you to accomplish this migration with far less engineering effort. It also enables you to focus on writing code instead of provisioning and managing infrastructure for both compute and database parts of your application.
If you want to have more control over the infrastructure, this application can be deployed with minor changes to AWS Fargate for enterprise application modernization.
To learn more, refer to the GitHub repository for step-by-step instructions and the sample code. A MongoDB Atlas free trial is available on AWS Marketplace.
MongoDB – AWS Partner Spotlight
MongoDB is an AWS Data and Analytics Competency Partner and developer data platform company empowering innovators to unleash the power of software and data.