Slide 1

Slide 1 text

Getting started with AWS Cloudformation using Python PyCon NG 2017 OMIDIORA Samuel DevOps Engineer @ TerragonGroup

Slide 2

Slide 2 text

Agenda ● What is AWS Cloudformation? ● Anatomy of a Cloudformation template ● What is Troposphere? ● Simple Template using Troposphere python library ● Quick AWS Walkthrough

Slide 3

Slide 3 text

What is 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 https://aws.amazon.com/cloudformation/

Slide 4

Slide 4 text

Anatomy of a Cloudformation Template ● Parameters ● Mappings ● Resources ● Outputs ● Conditions

Slide 5

Slide 5 text

- Parameters Parameters section is used to pass values into your template when you create a stack. "Parameters" : { "InstanceTypeParameter" : { "Type" : "String", "Default" : "t2.micro", "AllowedValues" : ["t2.micro","m1.small", "m1.large"], "Description" : "Enter t2.micro, m1.small, or m1.large. Default is t2.micro." } } http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html ANATOMY OF A CLOUDFORMATION TEMPLATE

Slide 6

Slide 6 text

- Mappings Mappings section matches a key to a corresponding set of named values. "Mappings" : { "RegionMap" : { "us-east-1" : { "32" : "ami-6411e20d"}, "us-west-1" : { "3a2" : "ami-c9c7978c"}, "eu-west-1" : { "32" : "ami-37c2f643"}, "ap-southeast-1" : { "32" : "ami-66f28c34"}, "ap-northeast-1" : { "32" : "ami-9c03a89d"} } } http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html ANATOMY OF A CLOUDFORMATION TEMPLATE

Slide 7

Slide 7 text

- Resources Resources section declares the AWS resources that you want to include in the stack, such as an Amazon EC2 instance or an Amazon S3 bucket. "Resources" : { "MyEC2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "ImageId" : "ami-2f726546" } } } http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html ANATOMY OF A CLOUDFORMATION TEMPLATE

Slide 8

Slide 8 text

- Outputs Outputs section declares output values that you can import into other stacks "Outputs" : { "InstanceID" : { "Description": "The Instance ID", "Value" : { "Ref" : "EC2Instance" } } } http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html ANATOMY OF A CLOUDFORMATION TEMPLATE

Slide 9

Slide 9 text

- Conditions Conditions section includes statements that is defined when a resource is created or when a property is defined. "Conditions" : { "CreateProdResources" : {"Fn::Equals" : [{"Ref" : "EnvType"}, "prod"]} }, http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html ANATOMY OF A CLOUDFORMATION TEMPLATE

Slide 10

Slide 10 text

What is Troposphere? The troposphere python library allows for easier creation of the AWS CloudFormation JSON by writing Python code to describe the AWS resources. Troposphere also includes some basic support for OpenStack resources. https://github.com/cloudtools/troposphere

Slide 11

Slide 11 text

Let’s create a sample Template

Slide 12

Slide 12 text

https://github.com/samparsky/cloudformation-template/blob/master/cloudformation.py Troposphere Demo

Slide 13

Slide 13 text

https://github.com/samparsky/cloudformation-template/blob/master/output.json

Slide 14

Slide 14 text

Let’s input our Sample Template into AWS https://samparsky.imgur.com/

Slide 15

Slide 15 text

#1

Slide 16

Slide 16 text

#2

Slide 17

Slide 17 text

#3

Slide 18

Slide 18 text

#4

Slide 19

Slide 19 text

#5

Slide 20

Slide 20 text

#6

Slide 21

Slide 21 text

#7

Slide 22

Slide 22 text

Wrap-up Using Troposphere makes it easy to ● Version Control ● Make it easy to test our IaC ● Don’t mix IaC and manual config Alternatives to AWS Cloudformation ● Terraform

Slide 23

Slide 23 text

Questions?

Slide 24

Slide 24 text

Thanks! Reach Me: Email: [email protected] Twitter : @samparsky