DEV Community

Cover image for Sexiest way to manage your AWS resources
jekobokidou for AWS Community Builders

Posted on

Sexiest way to manage your AWS resources

A friend has been editing a SaaS solution for a few years on AWS Cloud. Step by step, his SaaS solution is starting to take hold, his client portfolio is growing, he has to hire more developers. The code that used to be modified by a single person will now be modified by several, so far its git repository is only composed of two branches “develop” for its developments and “main” for what goes into production.

Suitable git flow for one single developer

This situation terribly anguishes him, he wonders if he will be able to scale up. So he asks me :

  • How can I manage the development of features in parallel?
  • How can I minimize the risks of regression?
  • How to carry out production releases with zero downtime?

The Gitflow like for bigger developers teams

Before answering those questions, I wanted to reassure him because being on AWS cloud is a great starting point. For sure AWS certainly has the most complete cloud ecosystem, and any SaaS application should feel safe there.
So I told him to close his eyes and imagine a solution able to dynamically :

  • Creates a "feature" branch from "develop"
  • Creates a "feature" dedicated environment on the AWS cloud
  • Create a deployment pipeline on the "feature" environment and which is triggered at each commit on the "feature" branch
  • Create a DNS record that allows easy testing of the "feature" branch
  • Create a load balancer and deploy an SSL certificate for the "feature" environment
  • Deploy in "Staging" with each validation of "merge request" carried out on the "develop" branch
  • Create an image of the "staging" environment for a deployment in production

Automating environment management

Then I told him to open his eyes, because it can easily be implemented on the AWS cloud, let’s deal with it.

How to Create a “feature” branch from “develop”?

Terraform is your friend, the code below allows you to have a Terraform module that allows you to manage any git repository.

Terrform code snippet to create or delete a git branch

How do I create a feature-dedicated environment on the AWS Cloud?

Terraform is once again your friend if you need to interact with AWS. All deployment models can be automated with Terraform:

  • EC2 servers
  • Docker containers on ECS
  • Docker containers on Kubernetes
  • Lambda functions
  • RDS databases
  • A combination of all these workloads

Terrform code snippet to create an EC2 instance

Terrform code snippet to create an AWS Fargate service for Docker containers

How do I create a deployment pipeline on the “feature” environment and which is triggered on commit on the “feature” branch?

Here again Terraform will allow you to automate the creation of a pipeline with the tool of your choice. But since you're on AWS, you can use Terraform to build a pipeline with AWS CodePipeline.

Terrform code snippet to create an AWS CodePipeline pipeline

How do I create a DNS record that makes it easy to test the "feature" branch?

We can definitely do everything with Terraform, because creating a DNS record on Amazon Route 53 is child's play.

Terraform code snippet to create a DNS record in a Route 53 hosted zone

How to create a Load Balancer and deploy an SSL certificate to it on the “feature” environment?

Terraform is once again the solution. All you need is to provide the ARN of your certificate.

Terraform code snippet to create an AWS ALB with an SSL certificate attached on it

How to automatically deploy each time a merge request is validated?

The validation of a "merge request" corresponds to a commit on the destination branch. With AWS CodePipeline and Terraform, automatic triggering of a pipeline execution is done by configuring a connection at the Source stage of your pipeline.

Using a codestar connection to trigger pipeline execution

How do I create an image of the staging environment for a production deployment?

With Terraform creating an AMI Image of an instance is easy, creating a Docker image is even easier.

Terraform code snippet to create an AMI

So what's the sexiest way to manage your AWS resources ?

All this code allows you to have scripts that will allow you to manage your resources, create new environments, streamline and enhance the work of your developers.
To go further, you can even develop a small “user friendly” application to control the execution of your scripts and thus control the management of a complex infrastructure with a click.

Managing IaC scripts

Then you entire architecture could look like this.

Solution architecture including a IaC tool to manage AWS cloud resources

Terraform is great

IaC tools are the perfect answer to manage Cloud resources. You can still have fun using the AWS Web Console, but tools like Terraform will makes you speed, go fast like Usain Bolt, and improve the maintainability, of your AWS Cloud infrastructure.

Top comments (0)