Skip links
Explore
Drag

Create a Static Source IP in AWS HA Environment + MongoDB Atlas (Part 1)

I don’t know who you are. I don’t know what you want. If you’re looking for ransom I can tell you I don’t have money but what I do have, are a very particular set of skills. Skills I have acquired over a very long career. Skills that make me a nightmare for people like you. If you’re not interested in what I have to say this will be the end of it but if you’re looking for a way to deploy a High Available Fault-Tolerant Elastic Beanstalk Environment that can connect with MongoDB Atlas. I will look for you. I will find you and I will help you.

Now I gotta admit this one gave me a little bit of trouble. For those of us who would like to create an environment that can easily scale but you don’t want the administrative overhead of managing your own infrastructure perhaps this article can help guide your way.

No alt text provided for this image

Well, that was me trying to deploy said environment in AWS and ran into a few hiccups. Maybe this can give you a headstart.

To an AWS expert, this might seem like a breeze but while I may know a thing or two about AWS, I am still working on that expert part. This article will show you how to deploy an application in Elastic Beanstalk that will read/write to MongoDB Atlas. Are we on the same page? Great!

Before we get into it let’s set the stage for some background knowledge. First of all, what’s an AWS, why and what’s an Elastic Beanstalk and can somebody tell what’s a MongoDB Atlas?

Amazon Web Service

AWS is short for Amazon Web Service. Amazon Web Services (AWS) is actually a child company of, you guessed it, AMAZON. These guys sell literally everything not just clothes and electronics from its e-commerce platform but they sell cloud computing as well with AWS. Amazon Web Services is the world’s most comprehensive and broadly adopted cloud platform, offering over 175 fully-featured services from data centers globally. Millions of customers—including the fastest-growing startups, largest enterprises, and leading government agencies—are using AWS to lower costs, become more agile, and innovate faster. – (AWS, 2020)

Sounds simple? It’s basically computing in the cloud. It offers a plethora of web services from cloud computing, storage, database to machine learning and many other services that can help your business to scale without the upfront cost of buying your own servers.

What can you do with AWS?

Let’s say you owned a small business or a big one and you have your own servers locally. It has done you well but now your business is growing and you’re definitely gonna need more servers. More servers to host your databases, enterprise applications and files. So what are you gonna do? Well, you can go ahead and order yourself a few of these babies, more routers, more switches, more wires, and a cisco certified expert to wire everything up for you $$$

No alt text provided for this image

or you can utilize AWS pay-as-you-go online web services and get all of this at your disposal

No alt text provided for this image

fully protected, fully scalable and fully disposable. You can run your web and application servers in the cloud to host dynamic websites. You can store large amounts of data in its online storage services. You can manage your own databases like MongoDB, PostgreSQL, MySQL or SQL Server. Without the upfront investment in buying additional servers yourself. AWS is not the only one of its kind they are other cloud computing platforms like:

and a lot more but these guys are on top so you have options. You typically choose based on the skills of your team, the services they offer and whether or not they can do what you need them to do. However, AWS has been leading the race and offers the most extensive services. It’s the best but do not quote me on that.

What is Elastic Beanstalk?

Like I said AWS offers a wide array of cloud computing services. Elastic Beanstalk is one of those services. With Elastic Beanstalk, you can quickly deploy and manage applications in the AWS Cloud without having to learn about the infrastructure that runs those applications. Elastic Beanstalk reduces management complexity without restricting choice or control. You simply upload your application, and Elastic Beanstalk automatically handles the details of capacity provisioning, load balancing, scaling, and application health monitoring. – (AWS, 2020).

Why Elastic Beanstalk?

Ok, I get what it does but why use it? Everything that AWS does with Elastic Beanstalk you can literally do it for yourself. You can set up your own load balancer, your own auto-scaling groups and provision your own instances, i.e virtual computers, and you can literally get the same result if you had the knowledge to do so.

Well, dependant on your scenario, that’s also the problem if you do it without Elastic Beanstalk. You have to set up EVERYTHING for yourself and based on your use case, meaning your team and your time that might be an issue. If you don’t have a System Admin, or a DevOps expert on standby it then becomes hassling to write code and maintain software infrastructure and everything that comes with continuous deployment processes. Many developers want to avoid dealing with the deep details of software infrastructure. Elastic Beanstalk provides a simple way in which you can deploy applications while leaving you to focus on what matters, customer feedback and building a great product.

MongoDB Atlas

MongoDB Atlas is MongoDB’s managed MongoDB as a Service. Basically, database-as-a-service. MongoDB is one of several NoSQL databases. This article doesn’t go in-depth with MongoDB that will require an article for itself. However, without getting too deep with the explanation, there is SQL (i.e SQL Server and MySQL) and NoSQL databases. Let’s leave it at SQL databases store data in tables and NoSQL databases store data in document format, like JSON. Crap, now I have to talk about what JSON is. See the more I talk about it the more new words pop up. If you want to know more just google 🙂 or check out this article “A Brief Introduction to NoSQL“.

Now back to Atlas. Atlas takes the responsibility of everything when it comes to MongoDB. From hosting, patching and managing to securing your MongoDB cluster. Remember that thing about use cases and time? With AWS, you can set up your own MongoDB database to your liking but then you would have to ensure to do the other things as well, like server hardening, patching, and security. With MongoDB Atlas, we can save a lot of time and headaches that come with managing our own databases and leave that up to other software vendors.

What are we designing?

Awesome, now we have covered all the major moving parts. We understand what the services above are and why you would use them. So lets the paint the scenario. You basically want to deploy a REST API application in AWS that will automate as much provisioning and scaling capabilities as possible to facilitate read/write actions to MongoDB Atlas. A visual reference of what that looks like can be seen here.

No alt text provided for this image

The Whitelisting IP Address Challenge

Great, we have a visual idea of what we need to design. So what’s the problem again? Well, we want to deploy a production-ready application. That means it needs to have a few things checked off when it comes to production readiness. You typically want to deploy an application that will meet the demand of all its users. Who likes software that takes forever to load because it can’t manage the load? So we need to deploy our application in a manner that will allow it to scale up when there is more traffic and to be able to scale down when there is less.

We can perform two types of scaling, horizontal scaling and vertical scaling. Horizontal scaling means that you scale by adding more of the same machines. If you had one server running your application now you will have two of the exact the same type. Vertical scaling means that you scale by adding more power to an existing machine. Meaning if you had one (1) CPU you would upgrade to two (2). If you had 8Gb of RAM you would upgrade to 16Gb. So you’re increasing the power of a single machine. With Elastic Beanstalk, it scales by adding more instances to your pool so it would perform horizontal scaling. Sure there are plenty of creative ways to perform scaling but let’s stick with the script. Docker anyone?

To connect to your MongoDB database you would need to whitelist the IP Address of the machines that will connect to it. This is a security measure to restrict network access to specific devices. You wouldn’t want your customer data exposed to the whole world, would you? We could simply add the IP address one by one of each machine as they come up but that manual process is borderline crazy and we would have to update the whitelist each time a new server has been added or removed. There must be a way to automate this process. AWS allows us to have static IP Addresses for every new instance that is created in an Elastic Beanstalk environment. That way regardless of how many instances that have been created each new instance will use the same static IP Address thereby allowing our API to connect to the DB regardless of how many servers it is deployed on.

Another way we could get our AWS Environment to connect with MongoDB Atlas is through VPC Peering. VPC Peering is perhaps a much easier way to perform the above. We can simply connect our MongoDB Atlas environment with the AWS environment and that would somewhat make the process easier. However, we are not covering this method here.

How to Create Source Static IP Address in AWS Elastic Beanstalk?

This is where I will lose most of you as it’s about to get super technical. Which it must in order for us to fully benefit. So thanks to all the PMs, Managers, Sales, interested tech folks and that one dude who always seems to be free of work thanks for sticking with me this far. It was fun. For the rest of us who want to wonder a little bit further let’s get into it. We will cover the rest in Part 2 where we will see how to set up our AWS environment to have a static source IP Address for any instance we create in Elastic Beanstalk.

Leave a comment