Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
AWS Certified Developer - Associate Guide - Second Edition

You're reading from  AWS Certified Developer - Associate Guide - Second Edition

Product type Book
Published in Jun 2019
Publisher Packt
ISBN-13 9781789617313
Pages 812 pages
Edition 2nd Edition
Languages
Authors (2):
Vipul Tankariya Vipul Tankariya
Profile icon Vipul Tankariya
Bhavin Parmar Bhavin Parmar
Profile icon Bhavin Parmar
View More author details

Table of Contents (30) Chapters

Preface 1. Overview of AWS Certified Developer - Associate Certification 2. Understanding the Fundamentals of Amazon Web Services 3. Identity and Access Management (IAM) 4. Virtual Private Clouds 5. Getting Started with Elastic Compute Cloud (EC2) 6. Handling Application Traffic with ELB 7. Monitoring with CloudWatch 8. Simple Storage Service, Glacier, and CloudFront 9. Other AWS Storage Options 10. AWS Relational Database Service 11. AWS DynamoDB - A NoSQL Database Service 12. Amazon Simple Queue Service (SQS) 13. Simple Notification Service (SNS) 14. AWS Simple Workflow Service (SWF) 15. CloudFormation Overview 16. Understanding Elastic Beanstalk 17. Overview of AWS Lambda 18. Key Management Services 19. Working with AWS Kinesis 20. Working with AWS CodeBuild 21. Getting Started with AWS CodeDeploy 22. Working with AWS CodePipeline 23. CI/CD on AWS 24. Serverless Computing 25. Amazon Route 53 26. ElastiCache Overview 27. Mock Tests 28. Assessments 29. Another Book You May Enjoy

CloudFormation Overview

AWS infrastructure can be created and customized using the AWS dashboard (GUI), CLI, or API. These methods may be able to build an infrastructure quickly as a one-off; however, over a long period of time, if used to create a whole or partial infrastructure repeatedly in a different region to build Disaster Recovery (DR), or in a subsidiary AWS account, then those methods would be costly, not only in terms of time and money, but also in terms of management, modification, and maintenance. It is a case of reinventing the wheel every time and it is error-prone. To resolve this issue, Amazon provides the CloudFormation service.

AWS CloudFormation allows you to create and customize the AWS infrastructure using code. It also enables you to create your infrastructure as code. This program or code is known as a template in AWS CloudFormation. These templates are...

Understanding templates

AWS CFT describes all AWS resources and their properties in JSON or YAML format. Templates can be written using any text editor. It is recommended that you give relevant and meaningful filenames to each template. Template extensions can be .json, .yaml, or .txt. When these templates are executed, the defined AWS resources are created in the respective AWS account. You can either upload the template to an S3 bucket and specify the template URL or you can upload the template file using the browse button in the template creation wizard. Even if you upload the template file using the browse button in the template creation wizard, it is internally stored in S3. The following diagram helps us to understand this:

Figure 15.1: The AWS CloudFormation flow
While creating a stack, if the template path is pointing to the local machine, then it will automatically...

Understanding a stack

A stack is created upon the successful execution of a template in CloudFormation. Executing a template creates a defined set of AWS resources. A group of these AWS resources defined in CloudFormation is called a stack. During template execution, if CloudFormation is unable to create any resource, the whole stack creation fails. When a CloudFormation execution fails, it rolls back all of the execution steps and deletes any resources created during the process. CloudFormation execution may fail due to several reasons, including insufficient privileges. Due to limited IAM privileges, if the rollback process is unable to delete the created resources, then the incomplete stack remains in the AWS account until it is deleted by an IAM user with sufficient privileges to delete the stack.

At the time of creating a stack from the template, AWS CloudFormation only checks...

The template structure

The following code block helps us to understand the basic AWS CFT structure in JSON and YAML format. For a basic AWS CloudFormation template structure in JSON and YAML, you can refer to https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html:

  • The JSON structure: The JSON structure is as follows:
{
"AWSTemplateFormatVersion" : "version date",
"Description" : "JSON string",
"Metadata" : {
template metadata
},
"Parameters" : { set of parameters
},
"Mappings" : { set of mappings
},
"Conditions" : {
set of conditions
},
"Transform" : { set of transforms
},
"Resources" : { set of resources
},
"Outputs" : {
set of outputs
}
}
  • The YAML structure: The YAML structure is as follows:
---
AWSTemplateFormatVersion: "version date"
Description...

A sample CloudFormation template

The following reference URLs provide various ready-to-use CFTs to match the general needs of an enterprise. These templates can be used directly or be modified as per the actual business need. Once templates are written, the partial code can be referred, or copied and pasted into another template for quickly creating new templates.

The following are important reference URLs for sample CFTs:

CloudFormer

CloudFormer can automatically generate a CFT from existing AWS resources in your AWS account. It stores the CFT in a target S3 bucket specified by you. Unlike writing a template from scratch, CloudFormer performs a reverse-engineering task and makes your life easier by generating a template from existing AWS resources in your account. This template can be used as it is for DR, or you can use them for customizing your infrastructure based on your needs. At the time of writing this book, CloudFormer is still in beta version.

Rolling updates for auto scaling groups

AWS CloudFormation provides you with a mechanism to control how an auto scaling group updates your resources using the UpdatePolicy attribute. If you do not configure your settings correctly, a rolling update on an auto scaling group may be performed unexpectedly. You can address this scenario by using the AutoScalingRollingUpdate policy, which supports a number of options to configure your template.

Here is an example of the updated policy for rolling updates, which can be found in official AWS documentation at https://aws.amazon.com/premiumsupport/ knowledge-center/auto-scaling-group-rolling-updates/. You can also refer to a very good article on rolling updates with CloudFormation at https://cloudonaut.io/ rolling-update-with-aws-cloudformation/.

CloudFormation best practices

CloudFormation best practices are as follows:

  • Always give meaningful and relevant names to AWS CloudFormation templates and resources.
  • Make sure the resources used by a CloudFormation template exist in the region where it is being executed to create a stack, for example, resources such as an EC2 key pair. It can be also be created dynamically using templates, but, if it is hardcoded, make sure it exists in the relevant region.
  • Write a template and create a stack for each layer, for example, a separate stack for web servers, application servers, and networks. It will help us to minimize downtime and efficiently manage and maintain infrastructures.
  • Use a cross-stack reference. This will help us to integrate resources from multiple templates into one template, especially when a separate stack is created for each layer.
  • It is best practice to provide...

Summary

  • CloudFormation can be used to create Infrastructure-as-Code (IaC).
  • AWS does not charge you for using the CloudFormation service.
  • AWS CFTs describes all AWS resources and their properties in JSON or YAML format.
  • You can either upload a CloudFormation template created locally or you can point to an S3 URL to create a CloudFormation stack.
  • Executing a CFT creates a defined set of AWS resources. A group of these AWS resources defined in CloudFormation is called a stack.
  • While creating a CloudFormation stack, if the template path is pointing to the local machine, then it will automatically upload the CloudFormation template to the AWS S3 bucket in the relevant region.
  • CloudFormation automatically identifies the resource dependencies and creates them sequentially.
  • Generally, it is recommended that you write a template for each layer of architecture, that is, the web layer and...
lock icon The rest of the chapter is locked
You have been reading a chapter from
AWS Certified Developer - Associate Guide - Second Edition
Published in: Jun 2019 Publisher: Packt ISBN-13: 9781789617313
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.
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 €14.99/month. Cancel anytime}