Site Loader

In this article, I am going to explain the advantages of automating our infrastructure in AWS using Cloud formation. First I am going to start off with a little comparison among Manual Work and Automation and how the automation can make us more productivity in our daily basis.

Automation vs Manual Work

The majority of the companies that start working in the Cloud started using the management console or Manual Work to create their infrastructure in the cloud but sooner or later we started facing some issues with the manual configuration, this is:

High costs: managing the infrastructure manually is inefficient because of the fewer controls.

Low Quality: any wrong configuration affect the applications and the final customer because in the manual work is too easy to make mistake.

Low Flexibility: Any change in the infrastructure is complex because there isn’t standardized automation that could help.

Automation, in the other hands, is the way to follow, they help us converting the best practices in guides to follow and avoid the failure repetition, giving us:

Better productivity: replacing the manual work improves the efficiency of the whole team.

Testing: We are able to test our infrastructure’s changes and avoid production problems.

Shared Knowledge: The way to manage the infrastructure is in code and is more easy to manage and maintain besides, the team is able to know from others member benefiting the company overall.

Cloud formation

Managing infrastructure in an automated way is an important key to success in AWS, the automation helps us improve the quality, reduce costs and improve flexibility but you may be asking yourself:

How can I automate my infrastructure?

The answer is simple, Cloud formation.

Cloud formation is a service tool offered by AWS to describe the infrastructure in code, you don’t need to know any programming language if you don’t want because the configuration can be made using simple JSON files.

But, how is possible that a JSON file transforms into infrastructure on AWS?

Well, this is because the AWS API which is the magic wound that creates all those components once we configure on JSON files. In order to be able to create your template in AWS once prepared, you are going to need to publish through the webpage or the AWS CLI (this one need to be installed on your machine and you need to create a token to be able to access to the resources).

In this article, I don’t pretend to teach you how to use AWS Cloudformation but I am going to give you a simple example to show the advantages of using this type of services on AWS Cloud.

In order to be able to use AWS from the CLI below is the information related:

CLI Installation: https://docs.aws.amazon.com/cli/latest/userguide/installing.html

CLI Authentication: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

Let’s see a demo

I am going to create the below infrastructure using Cloudformation:

The JSON template for fulfilling the image below is this:

https://github.com/edgarleonardo/cloud_formation_examples/blob/master/nodeserver/node-webserver.json

Now let’s explain the components inside the JSON:

AWSTemplateFormatVersion: this is the version of the template, the only that exists is 2010–09–09.

Description: here we add a description for the template.

Mappings: this is a place where we add constant to be used throughout the template’s resources.

Resources: Here are all AWS components and their interactions, cloud formation manage all dependency among components in an easy way, as we can see in the JSON there are:

  1. VPC: is the base of all components on AWS, here are located the different resources.
  2. EC2Instance: is the Virtual Machine that will run our node application.
  3. InternetGateway: is the component that allows us to get to the internet.
  4. VPCGatewayAttachment: is the attachment between VPC and InternetGateway.
  5. WebServerSubnet: this is where the network is configured.
  6. Route Table: is the routing table that allows the communications among components inside a VPC.
  7. NetworkAcl: is the access list that is configured to protect the access to the resource on our server.

When we finish up our template we just run the next script from the CLI:

Creating the stack on AWS from CLI:
aws cloudformation create-stack — stack-name node-server — template-body file://node-webserver.json

For checking if the stack is already created from CLI:
aws cloudformation describe-stacks

For Deleting the stack from CLI:
aws cloudformation delete-stack — stack-name node-server

When the stack is finished, you will be able to see the components created in AWS.

Here are two more examples of Cloud Formations: https://github.com/edgarleonardo/cloud_formation_examples

Post Author: Edgar Leonardo

I am Full Stack Developer and DevOps passionate, result-driven with deep experience on IT concerns. I am always seeking the best knowledge and practices in the world of technologies that make me and my work improve every day.

With more than 10 years of experience working as an IT professional, I have been involved and in some case leading large-scale IT projects since Backend, Frontend, Mobile Applications, Cloud Solutions and API integrations and even DevOps for Latam and the Caribbean in areas like Finance, Banking, Digital Advertising, Search engines, Social Network, Software Development, Outsourcing and Freelancer, integrations and more.