Book Image

Mastering AWS CloudFormation

By : Karen Tovmasyan
Book Image

Mastering AWS CloudFormation

By: Karen Tovmasyan

Overview of this book

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.
Table of Contents (17 chapters)
1
Section 1: CloudFormation Internals
4
Section 2: Provisioning and Deployment at Scale
9
Section 3: Extending CloudFormation

Introducing cfn-init

CloudFormation is a declarative instrument. This means that everything in your template is a declaration of what should be there in CloudFormation's state. And since you use resource attributes to declare your infrastructure, you must store your configuration in it as well, whether it's a source code in a Lambda function or user-data in an EC2 launch template, launch configuration, or instance.

Using user-data is a very simple process, but it is hard to declare a configuration in it. In the end, you will do a lot of shell programming, which is not as reliable as configuration management should be.

Luckily, CloudFormation has a set of so-called helper scripts—instruments that can get the data from CloudFormation's metadata or a stack, process it and perform operations on your resources. One of them is called cfn-init.

Important note

The cfn-init instrument (and any other helper script) is only included in Amazon Linux AMIs as a...