making web stack tasty using cloudformation

25
Making Web Stack tasty using Cloudformation and some other ingredients.. ..while watching pictures of food

Upload: nicola-salvo

Post on 02-Jul-2015

200 views

Category:

Technology


1 download

DESCRIPTION

Building an automatic and repeatable Web Stack using AWS technologies with a focus on leveraging AWS Cloudformation to layer environments for easy change and reuse.

TRANSCRIPT

Page 1: Making web stack tasty using Cloudformation

Making Web Stack tasty using Cloudformation and some other ingredients..

..while watching pictures of food

Page 2: Making web stack tasty using Cloudformation

● Who am I?● Layered stacks● Cooking tools● Lesson learned● Q&A

Outline

Page 3: Making web stack tasty using Cloudformation

Who am I?

Page 4: Making web stack tasty using Cloudformation

May contain traces of JSON and Python

Page 5: Making web stack tasty using Cloudformation
Page 6: Making web stack tasty using Cloudformation
Page 7: Making web stack tasty using Cloudformation
Page 8: Making web stack tasty using Cloudformation

Cooking tools

Page 9: Making web stack tasty using Cloudformation

Cloudformation

● Describe resources in a template● Supports most AWS services● Infrastructure as code

○ Reusable!

Resources:http://goo.gl/IS68OZ and http://goo.gl/11iWau

Page 10: Making web stack tasty using Cloudformation

Why Use It?

● Controllable and predictable● Saves time● Dev, Staging, Prod● Modular

Page 11: Making web stack tasty using Cloudformation

Anatomy of Cloudformation

● Parameters - up to 60 nowadays● Mapping - Regional AMIs, NAT instances● Resources - Bulk of the template● Outputs - Endpoints, IDs for reference

Page 12: Making web stack tasty using Cloudformation

● Params: CIDR, NAT AMI ID, NAT EIP,● Resources:VPC, Subnets, Security groups,

NAT ● Output: VPC ID, Subnet IDs

10_vpc_layer.json

Page 13: Making web stack tasty using Cloudformation

20_db_layer.json

● Params: VPC IDs, Subnet ID for DB, DNS for DB, DB size, DB name, DB admin etc

● Resources: RDS● Output: RDS endpoint

Page 14: Making web stack tasty using Cloudformation

● Params: VPC IDs, Subnet ID for webserver, autoscaling min/max etc.

● Resources: Autoscaling group, ELB, Ec2 instances.

● Output: ELB endpoint

30_web_layer.json

Page 15: Making web stack tasty using Cloudformation

"Resources" : { "MyEc2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "ImageId" : "ami-a921dfde", "KeyName" : "myec2key", "InstanceType" : "m1.small", "SecurityGroups" : [{ "Ref" : "Ec2SecurityGroup" }], } },

....

Page 16: Making web stack tasty using Cloudformation

"Resources" : { "MyEc2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "ImageId" : { "Ref" : "ImageIdParam" }, "KeyName" :{ "Ref" : "KeyNameParm" }, "InstanceType" :{ "Ref" : "InstanceTypeParam" }, "SecurityGroups" : [{ "Ref" : "Ec2SecurityGroup" }], } },

....

Additional snippets: http://goo.gl/Gj0JI0

Page 17: Making web stack tasty using Cloudformation
Page 18: Making web stack tasty using Cloudformation

Troposphere

Python Vs JSON

Installation:sudo pip install troposphere --upgrade

Objects Vs TextImport Vs Copy/Paste

Page 19: Making web stack tasty using Cloudformation

From troposphere to cloudformation

10_vpc.py

20_web.py

30_db.py

10_vpc.json

20_web.json

30_db.json

print template.to_json()

Page 20: Making web stack tasty using Cloudformation

from troposphere import FindInMap, GetAtt, Join,Parameter, Output, Ref,

Select, Tags, Template

import troposphere.ec2 as ec2

...

ec2_instance = template.add_resource(ec2.Instance(

"MyEc2Instance",

ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),

InstanceType=Ref(instancetype_param),

KeyName=Ref(keyname_param),

SecurityGroups =Ref(ec2_sg),

))

Example

Page 21: Making web stack tasty using Cloudformation

Gluing it together..

AWS Command line:unified tool to manage AWS resources, including Cloudformation

Installation:sudo pip install awscli --upgrade

Additional resources:http://goo.gl/PLkbfI

Page 22: Making web stack tasty using Cloudformation

● Create cloudformation:○ python 10_vpc.py > 10_vpc.json;

● Copy to S3:○ aws cp 10_vpc.json s3://bucket/10_vpc.json;

● Instantiate template:○ aws cloudformation create-stack --stack-name 10-VPC --

template-url bucketurl --parameter vpc_params.json --capabilities CAPABILITY_IAM

Gluing it together..

Page 23: Making web stack tasty using Cloudformation

Lesson learned

● Parameterize● Avoid layer dependency● Handle updates with care

○ Resource protection

Page 24: Making web stack tasty using Cloudformation

Questions??

Page 25: Making web stack tasty using Cloudformation

Get in touch

LinkedIn: https://www.linkedin.com/in/nicolasalvo

Twitter: @cloudreach

Website: www.cloudreach.com