Reader small image

You're reading from  AWS Certified Solutions Architect ??? Associate Guide

Product typeBook
Published inOct 2018
PublisherPackt
ISBN-139781789130669
Edition1st Edition
Tools
Right arrow
Authors (2):
Gabriel Ramirez
Gabriel Ramirez
author image
Gabriel Ramirez

Gabriel Ramirez is a passionate technologist with a broad experience in the Software Industry, he currently works as an Authorized Trainer for Amazon Web Services and Google Cloud. He is holder of 9/9 AWS Certifications and does community work by organizing the AWS User Groups in Mexico.
Read more about Gabriel Ramirez

Stuart Scott
Stuart Scott
author image
Stuart Scott

Stuart Scott is the AWS content lead at Cloud Academy where he has created over 40 courses reaching tens of thousands of students. His content focuses heavily on cloud security and compliance, specifically on how to implement and configure AWS services to protect, monitor and secure customer data in an AWS environment. He has written numerous cloud security blogs Cloud Academy and other AWS advanced technology partners. He has taken part in a series of cloud security webinars to share his knowledge and experience within the industry to help those looking to implement a secure and trusted environment. In January 2016 Stuart was awarded 'Expert of the Year' from Experts Exchange for his knowledge share within cloud services to the community.
Read more about Stuart Scott

View More author details
Right arrow

Working with Infrastructure as Code

Infrastructure as Code (IaC) has become a wide adopted practice in the IT industry because it provides systems with a consistent way to describe desired states for different purposes. IaC solves many of the problems encountered with manual operations like low consistency between deployments, stale documentation, and error operations. This practice is done based on two important pillars: automation and APIs. This is why cloud computing makes a total sense for this activity. AWS provides every service as an API and automates operations by providing several services like CloudFormation.

Treating infrastructure as code makes a total sense from the software engineering perspective. Software is reusable and modular. It can be designed to be loosely coupled and with high cohesion. This chapter focuses on the IaC practice from the CloudFormation service...

Technical requirements

There are no technical requirements for this chapter.

AWS CloudFormation

CloudFormation supports two standard formats, JSON and YAML. Personally I find YAML cleaner. YAML is a full serialization language with robust features and it also supports comments. We will use the YAML format for the following examples. For a quick reference to YAML format use this repo. It is a good idea to use a text editor; let's learn the hard way and use a simple text editor to learn pragmatically by doing lots of templates. Atom and Sublime Text are good editors. For YAML, the spacing convention is important and these editors will help you to do it easily.

To get started let's create the simplest template possible, s3-bucket.yaml (https://github.com/gabanox/Certified-Solution-Architect-Associate-Guide/blob/master/chapter20/s3-bucket.yaml):

Navigate to CloudFormation | Create Stack and choose the option to upload template to S3. This will...

Helper scripts

CloudFormation is an API based interface for managing resources and every resource is an object with properties and behavior. But what happens with resources like EC2 instances where CloudFormation doesn't have any control over the operating system and internal processes? The instance status changes to Running and CloudFormation understands that the final state of the object has been reached successfully.

Amazon Linux images incorporate scripts to perform the following activities:

    cfn-init

Installs software packages, parses metadata, creates files into disk, and configures operating system services declaratively.

In the previous example, the AWS::CloudFormation::Init type will do the following activities:

  • Install the httpd server using the latest stable version using the yum package manager
  • Create the file /var/www/html/index.html with the content string...

Multi-tier web app

Our last example consists of a three tier web app that incorporates multiple concepts that were addressed in this chapter. To demonstrate this functionality, we will use the OpsWorks VPCELB template. Several templates grouped by category can be viewed from the following documentation page: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/sample-templates-services-us-west-2.html#w2ab1c23c48c13c25.

AWS OpsWorks is a configuration management service that works with Chef and Ansible. Choose the basic AWS OpsWorks stack to create the EC2 instances layer and deploy a PHP application.

When the application is fully deployed, navigate to the OpsWorks menu in the AWS console and click on Go to my stacks. Here we can see CloudFormation has created the OpsWorks stack and deployed the application.

Use the ELB link to navigate to your web app, as shown in...

Summary

In this chapter, you learned the basic principles of the Infrastructure as Code practice by automating ops with AWS CloudFormation. We started with the simplest infrastructure as code that can be used to create AWS resources and manage changes to streamline the change management process.

We took a deep dive to the CloudFormation templates and usage of the most used elements and created a full three tier web application.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
AWS Certified Solutions Architect ??? Associate Guide
Published in: Oct 2018Publisher: PacktISBN-13: 9781789130669
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Gabriel Ramirez

Gabriel Ramirez is a passionate technologist with a broad experience in the Software Industry, he currently works as an Authorized Trainer for Amazon Web Services and Google Cloud. He is holder of 9/9 AWS Certifications and does community work by organizing the AWS User Groups in Mexico.
Read more about Gabriel Ramirez

author image
Stuart Scott

Stuart Scott is the AWS content lead at Cloud Academy where he has created over 40 courses reaching tens of thousands of students. His content focuses heavily on cloud security and compliance, specifically on how to implement and configure AWS services to protect, monitor and secure customer data in an AWS environment. He has written numerous cloud security blogs Cloud Academy and other AWS advanced technology partners. He has taken part in a series of cloud security webinars to share his knowledge and experience within the industry to help those looking to implement a secure and trusted environment. In January 2016 Stuart was awarded 'Expert of the Year' from Experts Exchange for his knowledge share within cloud services to the community.
Read more about Stuart Scott