Find out how to create automated infrastructure deployments using versioned Infrastructure as Code - CloudFormation templates on AWS. This talk will walk through two example CloudFormation templates. The first template will show how to use CloudFormation via AWS cli commands to create a Chef Server 12 instance and have it upload it’s client validation pem into private S3 bucket also created by the template. The second template will show how to use CloudFormation to create multiple client node instances in AWS EC2 and have them automatically bootstrap into the new Chef 12 Server instance. Links will be provided to the CloudFormation template code used for the demo for example purposes.
https://youtu.be/WXLDdGxfEsI
3. Infrastructure as Code is….
• A technical domain revolving around building and managing
infrastructure programmatically.
• A way to enable the reconstruction of the business from
nothing but a source code repository, an application data
backup, and bare metal resources.
• Your primary constraint should be the amount of time it
takes to restore your application data.
4. AWS CloudFormation: Infrastructure as Code
AWS CloudFormation gives developers and systems
administrators an easy way to create and manage a
collection of related AWS resources, provisioning and
updating them in an orderly and predictable fashion
First released in 2010
5. Amazon CloudFormation
• Infrastructure as Code
• Integrates with version control
• JSON formatted documents
• Templates for repeatable infrastructure
• Stacks of resources
• Supports AWS resource types
AWS CloudFormation
6. AWS CloudFormation: Infrastructure as Code
Document, version control, and share your applications
and infrastructure as a JSON document
Provision app and other AWS resources (VPC,
DynamoDB, RDS< EC2, Security Groups,) from a template
Repeatable, reliable deployments for test/dev/prod in
any AWS Region
8. AWS CloudFormation: Application stack example
(continue)
Template File
Defining Stack
Git
Subversion
Mercurial
Dev
Test
Prod
The entire application can be
represented in an AWS
CloudFormation template.
Use the version
control system of
your choice to store
and track changes to
this template
Build out multiple
environments, such
as for Development,
Test, and Production
using the template
11. {
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Example CloudFormation to install Chef 12 Server using RHEL 6.5 ami in us-east-1. This template creates and starts
a Chef 12 Server with the Web Management module (for up to 10 hosts), initializes knife in ec2-user account, and then uploads the
aws cookbook to the running Chef 12 Server. Roles are used to create a private s3 bucket and upload a client validation key. A
WaitCondition is used to pause the stack creation until the server is completely deployed. **WARNING** This template creates one or
more Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters": {
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the Chef Server",
"Type": "String",
"MinLength": "1",
"MaxLength": "255",
"AllowedPattern" : "[x20-x7E]*",
"ConstraintDescription" : "can contain only ASCII characters."
},
"InstanceType" : {
"Description" : "Chef 12 Server EC2 instance type",
"Type" : "String",
"Default" : "m3.large",
"AllowedValues" : [ "t2.micro","t2.medium","m3.medium","m3.large","m3.xlarge","m3.2xlarge"],
"ConstraintDescription" : "must be a valid EC2 instance type."
},
CloudFormation Chef Server 12 Example 1/7
12. "ChefServerRole" : {
"Description" : "Pre-create a Role - it needs at least S3 put/get",
"Type" : "String"
},
"SourceLocation" : {
"Description" : "Source IP address range allowed SSH/Web to the Chef Server",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"Default": "0.0.0.0/0",
"AllowedPattern": "(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})/(d{1,2})",
"ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
}
},
"Mappings" : {
"AWSRegion2AMI" : {
"us-east-1" : { "id" : "ami-00a11e68" }
}
},
CloudFormation Chef Server 12 Example 2/7
25. {
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Sample template to bring up a redhat linux ec2 instance and bootstrap a client node to be managed by an existing Chef
Server. **WARNING** This template creates an EC2 instance. You will be billed for the AWS resources used if you create a stack from
this template.",
"Parameters": {
"KeyName": {
"Type": "String",
"Description" : "EC2 KeyPair to enable SSH access to the client instance"
},
"InstanceType": {
"Default": "m3.medium",
"Description" : "Type of EC2 instance for the client node",
"Type": "String",
"AllowedValues" : [ "t2.micro", "t2.medium", "m3.small", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge"],
"ConstraintDescription" : "must contain only alphanumeric characters."
},
CloudFormation for Chef Clients in AWS 1/3
26. "ServerURL" : {
"Description" : "Chef 12 Server URL",
"Type": "String"
},
"ChefSecurityGroup" : {
"Description" : "Security group for clients to get access to Chef Server",
"Type": "String"
},
"S3Role" : {
"Description" : "IAM S3 Role with Get access for chef client bootstrapping automation",
"Type" : "String"
},
"ChefKeyBucket" : {
"Description" : "S3 bucket with validation key",
"Type": "String"
},
"ChefClientEnv" : {
"Description" : "Environment setting for deployed instances",
"Type": "String",
"Default" : "_default"
}
},
CloudFormation for Chef Clients in AWS 2/3
33. CloudFormation = Easy Teardown
• Fully automated
• Delete resources
• Complete teardown
• Entire stacks are disposable
• For this Chef 12 Example – Deleting clients in
CloudFormation automatically deregisters nodes
from Chef Server managementAWS CloudFormation
40. Thank you & Have fun!
Scott McDonald - smcdon@amazon.com
Editor's Notes
Notes:
The entire application can be represented in an AWS CloudFormation template.
You can use the version control system of your choice to store and track changes to this template.
You can use the template to quickly build out multiple environments, such as for Development, Test, and Production.