The Fastest Way To Get Your Application Up And Running!
Let’s be honest, developing web apps, and APIs and at the same time setting up, and maintaining the infrastructure is not often an easy task.
I’ve been in that position both as a software engineer and a DevOps. One of the services I relied on when it comes to pushing apps to production quicker is AWS Elastic Beanstalk.
In this tutorial, I’d like to walk you through 5 steps to make your application deployment as easy as possible.
1- Use Docker
AWS Elastic Beanstalk offers a variety of platforms on which you can build your applications. It supports applications built in Go, Java, .NET, Node.js, PHP, Python, and Ruby.
But the wonderful thing about AWS Beanstalk is that you can use Docker to spin up an environment of containers serving your app and that’s one of the things that make Beanstalk the way to go for a lot of developers.
No need to demonstrate why Docker is a must-used tool today. Docker has literally changed the way we develop and run apps even in production. Not only does using Docker ensure consistency across multiple developments and release cycles, but it also allows you to build a development environment in a matter of minutes and ease the CI/CD workflow of your applications. And there are tons of other advantages of using Docker.
So the first thing we should do to take full advantage of Beanstalk will be to Dockerize our apps.
That’s said, let’s tackle the next thing to do.
2- Use Docker Compose both in Development and in Production
Most of the applications today are multi-tiers.
So the next thing we need to do is to build a multi-containers environment for our dev and production environments.
Docker Compose helps a lot with that.
Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down. — Docker Official documantation.
Writing a docker-compose file is pretty straightforward on local. And the good news: AWS allows you to use a docker-compose file to build up your environment on production.
But hold on friend. There are some changes that needed to be made in your docker-compose file from local to production before getting everything up and running on Beanstalk.
Here are some key elements to take a look at before pushing your docker-compose file to AWS Beanstalk:
- container_name (on local), you should use hostname instead on AWS Beanstalk — hostname is also available on Docker-compose from version 3.
- mem_limit: 128m (on AWS Beanstalk).
On local, it should be:
And the funny thing is that on AWS Beanstalk it seems this is — I’m not quite sure — required.
3- Use a Private Docker Repository
Most of the time, while working with real applications, we need to store our built Docker images on private repositories.
In order to let AWS Beanstalk pull these images, we have to let it authenticate first.
The AWS Beanstalk official documentation recommends two ways of doing that:
- Using AWS Systems Manager (SSM) Parameter Store or
- Generating a docker.conf file issued by a Docker login process and then uploading it to an S3 bucket before calling it in a Docker Dockerrun.aws.json v3 file.
The first option fits our need since we decided to stick with a docker-compose file.
Here is the guide to how to proceed with the AWS SSM Parameter Store.
4- Connect your environment with a Git Repository
This is one of the best parts of making this process easier and more effective. Since we decided to use Docker, we need to set up a pipeline that can:
- Run various tests and checks.
- Build our Docker image(s) and push them on a repository.
- Push our docker-compose.yaml file to AWS Beanstalk.
I’m used to using Github Actions and Travis CI but CodePipeline is a good alternative to try (BTW now I’m thinking about giving it a try 🤔).
Now that we have a workflow that pushes our changes to Beanstalk, we do not need to think of how to deploy code anymore.
📌 One of the tips on Beanstalk is to version control every deployment we make either using the exact time or any unique ID.
5- Handle Your SSL/TLS Certificate With AWS Certificate Manager
One of the reasons I like using Cloud providers like AWS is their ability to offer a whole environment with many services you need to get your app ready to serve your customers.
Now that the app is deployed and running, we need to redirect traffic from our custom domain to the app domain given by Beanstalk. That’s a snap. But now we’d like to enable an encrypted connection for users using our app.
AWS Certificate Manager is a service that lets you easily provision, manage, and deploy public and private Secure Sockets Layer/Transport Layer Security (SSL/TLS) certificates for use with AWS services and your internal connected resources. — AWS Official Documentation
This guide gives all the details about requesting a certificate from AWS Certificate Manager.
Once the certificate is issued, you can use it to add a secure endpoint to your AWS Beanstalk load balancer.
And tada !!!
We have our application up and running and we can simply merge changes from our git repository and the changes will get deployed.
Beanstalk is a pretty good black box for developers. But even DevOps can take advantage of it by customizing a whole lot of things.
In this tutorial, we walked through how to make the deployment of our code easier and as effective as possible using Beanstalk with other tools.
So it’s maybe the right time to give it a try. If you need any help with migrating your app to AWS Beanstalk with a fully automated CI/CD, feel free to drop me a message in the comments or on Linkedin.
Till next time, take care.