Weitere ähnliche Inhalte Ähnlich wie Making web stack tasty using Cloudformation (20) Kürzlich hochgeladen (20) Making web stack tasty using Cloudformation1. Making Web Stack tasty using
Cloudformation and some other
ingredients..
..while watching pictures of food
2. Outline
● Who am I?
● Layered stacks
● Cooking tools
● Lesson learned
● Q&A
9. Cloudformation
● Describe resources in a template
● Supports most AWS services
● Infrastructure as code
○ Reusable!
Resources:
http://goo.gl/IS68OZ and http://goo.gl/11iWau
10. Why Use It?
● Controllable and predictable
● Saves time
● Dev, Staging, Prod
● Modular
11. Anatomy of Cloudformation
● Parameters - up to 60 nowadays
● Mapping - Regional AMIs, NAT instances
● Resources - Bulk of the template
● Outputs - Endpoints, IDs for reference
13. 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
14. 30_web_layer.json
● Params: VPC IDs, Subnet ID for webserver,
autoscaling min/max etc.
● Resources: Autoscaling group, ELB, Ec2
instances.
● Output: ELB endpoint
15. "Resources" : {
"MyEc2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : "ami-a921dfde",
"KeyName" : "myec2key",
"InstanceType" : "m1.small",
"SecurityGroups" : [{ "Ref" : "Ec2SecurityGroup" }],
}
},
....
16. "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
18. Troposphere
Python Vs JSON
Objects Vs Text
Import Vs Copy/Paste
Installation:
sudo pip install troposphere --upgrade
19. 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()
20. Example
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),
))
21. 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
22. Gluing it together..
● 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
23. Lesson learned
● Parameterize
● Avoid layer dependency
● Handle updates with care
○ Resource protection
25. Get in touch
LinkedIn: https://www.linkedin.com/in/nicolasalvo
Twitter: @cloudreach
Website: www.cloudreach.com