Mastering AWS CloudFormation

Book description

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.

Table of contents

  1. Mastering AWS CloudFormation
  2. Why subscribe?
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Code in Action
    6. Download the color images
    7. Conventions used
    8. Get in touch
    9. Reviews
  8. Section 1: CloudFormation Internals
  9. CloudFormation Refresher
    1. Technical requirements
    2. Understanding the internals of AWS CloudFormation
    3. Creating your first stack
    4. Understanding CloudFormation IAM permissions
    5. Drift detection
    6. Summary
    7. Questions
    8. Further reading
  10. Advanced Template Development
    1. Technical requirements
    2. Going through the internals of the template
      1. AWSTemplateFormatVersion
      2. Description
      3. Metadata
      4. Parameters
      5. Mappings
      6. Conditions
      7. Transform
      8. Resources
      9. Outputs
    3. Creating reusable templates
    4. Using conditional elements
    5. Deletion policies
    6. Referring to existing stacks
    7. AWS pseudo parameters
      1. AWS::AccountId
      2. AWS::NoValue
      3. AWS::Region
      4. AWS::StackId and AWS::StackName
      5. AWS::URLSuffix
      6. AWS::Partition
    8. Dynamic references with Parameter Store and Secrets Manager
    9. Summary
    10. Questions
    11. Further reading
  11. Section 2: Provisioning and Deployment at Scale
  12. Validation, Linting, and Deployment of the Stack
    1. Technical requirements
    2. Validating the template
    3. Using a linter for best practices on templates
      1. Linting against specific regions
      2. Ignoring specific rules
      3. Creating custom rules
    4. Provisioning our stack
      1. Deploying stacks using Change Sets
    5. Handling errors
    6. Working with drifts
    7. Summary
    8. Questions
    9. Further reading
  13. Continuous Integration and Deployment
    1. Technical requirements
    2. Including a template in your application
    3. Running smoke tests on your stack
      1. Smoke testing for EC2 auto scaling groups
      2. Smoke testing VPC resources
    4. Best practices for the release management of CloudFormation stacks
      1. Always use version control systems
      2. Ensuring that your dependencies can be easily retrieved
      3. Keeping your code base clean
      4. Choosing a proper branching model
      5. Always perform a code review
      6. Having full test coverage
      7. Don't forget to use a CloudFormation IAM role
      8. Always perform smoke testing
      9. Using the correct CI/CD instruments
      10. Keeping up the good work
    5. Creating a CI/CD pipeline with CloudFormation and CodePipeline
      1. Scenario – core stack
    6. Summary
    7. Questions
    8. Further reading
  14. Deploying to Multiple Regions and Accounts Using StackSets
    1. Technical requirements
    2. The old-fashioned way of multi-regional and multi-account infrastructure management
    3. Introducing StackSets
      1. Permissions
    4. Deploying to multiple regions
      1. Using AWS Console
      2. Using awscli
    5. Best practices for StackSets
    6. Deploying to multiple accounts
    7. Preventing failures of multiple StackSet deployments using TAGs
    8. Summary
    9. Questions
    10. Further reading
  15. Configuration Management of the EC2 Instances Using cfn-init
    1. Technical requirements
    2. Introducing cfn-init
    3. Deploying your application to EC2 during stack creation
      1. Creating a Hello, World application
      2. Creating LNMP stack
    4. Using cfn-signal to inform CloudFormation about resource readiness
    5. Summary
    6. Questions
    7. Further reading
  16. Section 3: Extending CloudFormation
  17. Creating Resources outside AWS Using Custom Resources
    1. Technical requirements
    2. Understanding custom resources
    3. The internals of the underlying Lambda function
    4. Writing and managing your own custom resource
      1. Creating databases in RDS using CRs
    5. Handling updates, deletions, and failures of CRs
      1. Deleting resource
      2. Updating resources
      3. Extra features for the custom database function
        1. Custom status reasons
        2. Sending a success upon the deletion of nothing
    6. Summary
    7. Questions
    8. Further reading
  18. Dynamically Rendering the Template Using Template Macros
    1. Technical requirements
    2. Understanding the use cases of the template macro
      1. Auto filling resource property values
      2. Adding extra resources
      3. Making resource declaration easier for developers
    3. Introducing the template macro
      1. Considerations
    4. Writing your own macro
      1. AMI ID filler
      2. Rendering the application template from a short declaration
        1. Parsing properties
        2. Declaring resources from the macro
        3. Deploying a standard app
    5. Summary
    6. Questions
    7. Further reading
  19. Generating CloudFormation Templates Using AWS CDK
    1. Technical requirements
    2. Introducing AWS CDK
    3. Facilitating template development with AWS CDK
    4. Writing your first template using AWS CDK and Python
      1. Preparing constructs
      2. Rendering core resources
      3. Rendering the web tier
      4. Rendering the storage tier
      5. Deploying CDK application
      6. Testing CDK applications
    5. Summary
    6. Questions
    7. Further reading
  20. Deploying Serverless Applications Using AWS SAM
    1. Technical requirements
    2. Introducing AWS SAM
    3. Understanding the differences between SAM and CloudFormation
    4. Writing your first serverless application with SAM
      1. Prerequisites
      2. Developing a Hello, World application
      3. Running SAM applications
      4. Examining logs with SAM
      5. Creating complex applications with SAM
    5. Summary
    6. Questions
    7. Further reading
  21. What's Next?
    1. The future of infrastructure as code
    2. Understanding the difference between Terraform and CloudFormation
      1. Provider support
      2. Declaration syntax
      3. Development and deployment methodologies
    3. Understanding the value of Cloud Development Kit
      1. Testing infrastructure
      2. Adding artifacts
    4. Summary
    5. Further reading
  22. Assessments
    1. Chapter 1: CloudFormation Refresher
    2. Chapter 2: Advanced Template Development
    3. Chapter 3: Validation, Linting, and Deployment of the Stack
    4. Chapter 4: Continuous Integration and Deployment
    5. Chapter 5: Deploying to Multiple Regions and Accounts Using StackSets
    6. Chapter 6: Configuration Management of the EC2 Instances Using cfn-init
    7. Chapter 7: Creating Resources outside AWS Using Custom Resources
    8. Chapter 8: Dynamically Rendering the Template Using Template Macros
    9. Chapter 9: Generating CloudFormation Templates Using AWS CDK
    10. Chapter 10: Deploying Serverless Applications Using AWS SAM
  23. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Mastering AWS CloudFormation
  • Author(s): Karen Tovmasyan
  • Release date: May 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781789130935