Swimminginthought

A place for all things technical and my mind..

Menu
  • About Me / Hire Me
Menu

Infrastructure as Code using AWS Cloudformation

Posted on September 10, 2019September 10, 2019 by Percy Kwong

Problem Statement

My Application is very complicated and it currently takes a lot of coordination and time to deploy my application.  Does that sound familiar? I think we’ve all lived that problem at least twice in our lives.  Deploying applications is never as easy as just double-clicking on “Setup.exe”, although it should be.

The Solution

The closest you’ll ever get to setup.exe is to implement Infrastructure as Code.  What **Exactly** does that mean?  It means assuming all the resources and assets are available, you can “one-step” configure, deploy, and test.   So.. In a nutshell; one-step.

IaC allows you to make a system / application call via a tool or API and provision / spin up VMs, Containers, Network Segments, Load Balancers, and Firewalls automatically.  The deployment will first provision the environment if needed (think about your vSphere, Xen, or Openstack cluster) or in the case of your cloud Azure or AWS, set up a VPC, apps, and everything else associated with it.

Many Paths to the same Destination

The great thing about theory is exactly that; it’s theory.  We can talk about it until we’re blue in the face, but what happens in the real world?  Just how difficult is it really to do this?  I’m the guy that says, “Let me put my money where my mouth is.”  I’m going to give you a couple of examples. So here’s the first one in the series.  I’ll be writing additional parts / articles in this series, but due to time constraints and for the sake of brevity, I’m keeping the example in this article simple to demonstrate that Cloudformation just isn’t as difficult as one would think.

The Use Case

Let’s make this really simple.  We’ll build some infrastructure and deploy the VM.  In it’s most simple terms, let’s build out a single VM and launch it in the us-east-1 region of AWS .

Let’s choose the application and since we’re on a blog, how about we use WordPress?  Our stack will consist of the following:

  • OS: AMI Linux

The Workflow

In our overly simple example, we will deploy and follow the below workflow:

  1. Deploy a VM with Amazon Linux.

AWS Cloudformation

AWS Cloudformation is one of the most common examples of how to implement a “stack” or a set of resources that are defined in a configuration file.  This allows us to pass the configuration file to AWS and the infrastructure itself will be instantiated (created).  The reasoning behind using Cloudformation is once the template has been created and tested, further testing down the road is reduced.  A known-good configuration is deployed to AWS and only topical functionality testing needs to be performed.  This will save a significant amount of time in not only deployment, but human error is removed from the equation.

Cloudformation can ingest .json and .yml configuration files.  I chose to use .yml here, because it’s easier to read and less confusing for human consumption.

**Hint:  Writing and Editing Cloudformation or other JSON / YML  configurations become much easier when you use your favorite IDE.  I’ve seen so many people struggle with this very thing in Notepad or Microsoft Word.  I personally use Visual Studio Code.

 

AWSTemplateFormatVersion: 2010-09-09
Description: This is a simple template to launch a single instance in us-east-1
Resources:
  WebServerInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0b69ea66ff7391e80
      InstanceType: t1.micro
      Tags:
        -
          Key: Name
          Value: My VM
        -
          Key: Project
          Value: My VM Project

 

 

This above Cloudformation script will simply launch a single instance using the Amazon Machine Image (AMI) of instance size (VM) t1.micro. The benefit of doing this will allow you to integrate a CICD pipeline and automate multiple deployments in multiple locations very quickly.

For example, to launch the above Cloudformation configuration, one would simply need to execute the following command:

aws cloudformation create-stack --template-body file:/my.cloudformation.configuration.yml --stack-name example-stack --parameters ParameterKey=KeyName,ParameterValue=tutorial ParameterKey=InstanceType,ParameterValue=t1.micro

This is done from any machine that has the aws CLI tools installed.  We can do more things with Cloudformation like set up a VPC, an Autoscaler, Load Balancer, add additional subnets and tiers to the application, but the point of this post is to show the power of Infrastructure as Code.  In a future post, I’ll write about n-tier applications in a completely secure Cloudformation script.  This will include everything from instantiating a full stack in a VPC, multiple application tiers, set up a load balancer and autoscaling, and defining Access Control Lists as well.

If you’re interested in discussing what the Cloud and Infrastructure as Code can do for you or you’re looking for an Architect / Solution provider, consider hiring me.

Cheers!

 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs
  • Resurrection of the Blog
  • Encryption type Matters with Deep Packet Inspection – solved
  • Completely off topic.. Just a personal note.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs

Recent Comments

  • Percy Kwong on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Nick Doelman on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Percy Kwong on International Text solutions – A solution
  • Muzahid Ul Islam on The Browser Wars; Which One is Best?
  • Muzahid Ul Islam on International Text solutions – A solution

Archives

  • September 2019
  • August 2019
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • August 2011
  • June 2011
  • March 2011
  • February 2011
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • January 2010
  • November 2009
  • October 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008

Categories

  • Activism
  • All
  • Amazon S3
  • Announcements
  • Apache
  • Apple
  • Applications
  • Automation
  • AWS
  • Azure
  • Backups
  • Blogging
  • Books
  • Bootcamp
  • CentOS – RHEL
  • Cloud Computing
  • Cloudformation
  • Consulting Advice
  • Craigslist
  • Databases
  • Deep Packet Inspection
  • Doing the right thing
  • e-Book Readers
  • E-Mail
  • EC2
  • energy-efficiency
  • environment
  • Expose
  • firewalls
  • General Observations
  • Hardware
  • Hope
  • Hosting
  • IaC
  • Important things to do in life
  • Infrastructure as Code
  • Kubernetes
  • Linux
  • Media and Encoding
  • Miscellany
  • Mobile Phones
  • MySql
  • Networking
  • Performance
  • Personal
  • pfsense
  • Politics
  • Privacy
  • Redundancy
  • Routers
  • security
  • SPAM
  • Tech that doesn't work like it should
  • Tips and Tricks
  • Tools that work
  • Tout
  • Video
  • Virtual Computing
  • VOIP-Voice Over IP
  • VPN
  • Web Browsers
  • Web Hosting
  • Websites
  • Windows
  • Wordpress

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2026 Swimminginthought | Built using WordPress and Responsive Blogily theme by Superb