Mastering AWS CloudFormation
eBook - ePub

Mastering AWS CloudFormation

Plan, develop, and deploy your cloud infrastructure effectively using AWS CloudFormation

Karen Tovmasyan

Share book
  1. 300 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering AWS CloudFormation

Plan, develop, and deploy your cloud infrastructure effectively using AWS CloudFormation

Karen Tovmasyan

Book details
Book preview
Table of contents
Citations

About This Book

Build scalable and production-ready infrastructure in Amazon Web Services with CloudFormation

Key Features

  • Leverage AWS CloudFormation templates to manage your entire infrastructure
  • Get up and running with writing your infrastructure as code and automating your environment
  • Simplify infrastructure management and increase productivity with AWS CloudFormation

Book Description

DevOps and the cloud revolution have forced software engineers and operations teams to rethink how to manage infrastructures. With this AWS book, you'll understand how you can use Infrastructure as Code (IaC) to simplify IT operations and manage the modern cloud infrastructure effectively with AWS CloudFormation.This comprehensive guide will help you explore AWS CloudFormation from template structures through to developing complex and reusable infrastructure stacks. You'll then delve into validating templates, deploying stacks, and handling deployment failures. The book will also show you how to leverage AWS CodeBuild and CodePipeline to automate resource delivery and apply continuous integration and continuous delivery (CI/CD) practices to the stack. As you advance, you'll learn how to generate templates on the fly using macros and create resources outside AWS with custom resources. Finally, you'll improve the way you manage the modern cloud in AWS by extending CloudFormation using AWS serverless application model (SAM) and AWS cloud development kit (CDK).By the end of this book, you'll have mastered all the major AWS CloudFormation concepts and be able to simplify infrastructure management.

What you will learn

  • Understand modern approaches to IaC
  • Develop universal and reusable CloudFormation templates
  • Discover ways to apply continuous delivery with CloudFormation
  • Implement IaC best practices for the AWS Cloud
  • Provision massive applications across multiple regions and accounts
  • Automate template generation and software provisioning for AWS
  • Extend CloudFormation with custom resources and template macros

Who this book is for

If you are a developer who wants to learn how to write templates, a DevOps engineer interested in deployment and orchestration, or a solutions architect looking to understand the benefits of managing infrastructure with ease, this book is for you. Prior understanding of the AWS Cloud is necessary.

]]>

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Mastering AWS CloudFormation an online PDF/ePUB?
Yes, you can access Mastering AWS CloudFormation by Karen Tovmasyan in PDF and/or ePUB format, as well as other popular books in Computer Science & Software Development. We have over one million books available in our catalogue for you to explore.

Information

Year
2020
ISBN
9781789135312

Section 1: CloudFormation Internals

In our first section, we will do a small refresher on CloudFormation. Later, we will dive deep into its core component – a template – and learn how to write universal, redundant, and reusable templates.
This section comprises the following chapters:
  • Chapter 1, CloudFormation Refresher
  • Chapter 2, Advanced Template Development
Chapter 1

CloudFormation Refresher

Cloud computing introduced a brand-new way of managing the infrastructure.
As the demand for the AWS cloud grew, the usual routine and operational tasks became troublesome. The AWS cloud allowed any type of business to rapidly grow and solve all the business needs regarding compute power; however, the need to maintain a certain stack of resources was hard.
DevOps culture brought a set of methodologies and ways of working, and one of those is called infrastructure as code. This process is about treating your infrastructure—network, virtual machines, storages, databases, and so on—as a computer program.
AWS CloudFormation was developed to solve this kind of problem.
You will already have some working knowledge of CloudFormation, but before we dive deep into learning advanced template development and how to provision at scale, use CloudFormation with CI/CD pipelines, and extend its features, let's quickly refresh our memory and look again at what CloudFormation is and how we use it.
In this chapter, we will learn the following:
  • The internals of AWS CloudFormation
  • Creating and updating a CloudFormation stack
  • Managing permissions for CloudFormation
  • Detecting unmanaged changes in our stack

Technical requirements

The code used in this chapter can be found in the book's GitHub repository at https://github.com/PacktPublishing/Mastering-AWS-CloudFormation/tree/master/Chapter1.
Check out the following video to see the Code in Action:
https://bit.ly/2WbU5Lh

Understanding the internals of AWS CloudFormation

AWS services consist of three parts:
  • API
  • Backend
  • Storage
We interact with AWS by making calls to its API services. If we want to create an EC2 instance, then we need to perform a call, ec2:RunInstances.
When we develop our template and create a stack, we invoke the cloudformation:CreateStack API method. AWS CloudFormation will receive the command along with the template, validate it, and start creating resources, making API calls to various AWS services, depending on what we have declared for it.
If the creation of any resource fails, then CloudFormation will roll back the changes and delete the resources that were created before the failure. But if there are no mistakes during the creation process, we will see our resources provisioned across the account.
If we want to make changes to our stack, then all we need to do is update the template file and invoke the cloudformation:UpdateStack API method. CloudFormation will then update only those resources that have been changed. If the update process fails, then CloudFormation will roll the changes back and return the stack to the previous, healthy, state.
Now that we have this covered, let's start creating our stack.

Creating your first stack

I'm sure you've done this before.
We begin by developing our template first. This is going to be a simple S3 bucket. I'm going to use YAML template formatting, but you may use JSON formatting if you wish:
MyBucket.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: This is my first bucket
Resources:
MyBucket:
Type: AWS::S3::Bucket
Now we just need to create the stack with awscli:
$ aws cloudformation create-stack \
--stack-name mybucket\
--template-body file://MyBucket.yaml
After a while, we will see our bucket created if we go to the AWS console or run aws s3 ls.
Now let's add some public access to our bucket:
MyBucket.yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: This is my first bucket
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
Let's run the update operation:
$ aws cloudformation update-stack \
--stack-name mybucket \
--template-body file://MyBucket.yaml
To clean up your workspace, simply delete your stack using the following command:
$ aws cloudformation delete-stack --stack-name mybucket
Let's now look at the CloudFormation IAM permissions.

Understanding CloudFormation IAM permissions

We already know that CloudFormation performs API calls when we create or update the stack. Now the question is, does CloudFormation have the same powers as a root user?
When you work with production-grade AWS accounts, you need to control access to your environment for both humans (yourself and your coworkers) and machines (build systems, AWS resources, and so on). That is why controlling access for CloudFormation is important.
By default, when the user runs stack creation, they invoke the API method cloudformation:CreateStack. CloudFormation will use that user's access to invoke other API ...

Table of contents