TA Section 2017-4-1 Zhenyu Zhao DevOps Engineer at HUIT Infrastructure Technology Services E-mail: zhenyu_zhao@harvard.edu
Agenda CloudFormation template anatomy: built-in functions, mappings, parameters How to update a stack without deleting it Demo Building a simple infrastructure from the scratch with VPC, subnet, route table, network ACL, security group, an EC2 instance with User Data Q & A
How CloudFormation Works
How CloudFormation Change Set Works
JSON Components Structurally, starts with an object and key-value pairs are building block and every item is represented by a string literal {} represents an object (like a dictionary of key-value pairs) [] represents an array (a list of string values) The goal is to represent data structure relationship Syntactically, JSON is straightforward. Semantically, it is up to JSON parser to interpreter the code. CloudFormation template uses JSON to structure the code
CloudFormatrion Boilerplate code See code File: boilerplate
Built-in functions, Mappings and Parameters Built-in Functions that we are using here: Ref Fn::FindInMap Fn::Join Fn::Select Fn::GetAZs Fn::Base64 Reference: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic- function-reference.html
Built-in functions, Mappings and Parameters Multi-dimentional data structure Analogous to Python dictionary data structure Always use Fn::FindInMap to look up a key
Built-in functions, Mappings and Parameters Dynamic and user-driven Always use Ref to return pointer to a parameter
Demo We are building a simple infrastructure from the scratch: A VPC A Internet gateway A public subnet A network ACL that is attached to the public subnet A route table that is attached to the public subnet A security group An EC2 instance with User Data to set up Apache, MySQL, & PHP zhen-ta-tempate5-base => zhen-ta-tempate5-update1 => zhen-ta-tempate5-update2 => zhen-ta-tempate5-update3 => zhen-ta-tempate5-update4 => zhen-ta-tempate5-update5 => zhen-ta-tempate5-update6
Q & A When creating a new CloudFormation stack, how do you correctly reference existing resources (such as a VPC or subnet) in your script? (From Harry) Can you have two AWS resource of same type with same value for the Name tag? where are the files from section stored on the course site? http://fas.harvard.edu/~zzhao
Q & A Can we get this vlcid using Parameters?Like a dropdown Explore the parameter type in AWS documentation Zhen, if “ZhenVPC” was an existing VPC in my account, would I just delete the “ZhenVPC” section you have in “Resources”?