Previous Lecture Complete and continue  

  CloudFormation (CF) Example and CF Structure

Let's take a look at this CloudFormation example, it's very easy and very simple. In this example, we are creating an S3 Bucket. If you watched AWS Introduction course, you did that and you saw me doing that via the web console, this is how you can do it with CloudFormation blueprints or you would find resources, inside you would put the name, which is HelloBucket and you would specify the type and you would see AWS::S3, so that's a common convention in AWS to define a resource, so the type of the resource would be S3, under the AWS and it's gonna be the Bucket under the AWS S3 resources.

The same blueprint, but in the YAML format, so YML file. The YAML format uses white space, but it's a little bit more eloquent, because there is no need for quotes or curly braces or parenthesis, but be careful that you don't introduce extra white space and indentation, because white space and indentation is part of the format, so where do you put this blueprint?

You have few choices, command line, AWS CLI, so you would use CloudFormation blueprint and AWS CLI to feed that into the platform, you can use Web console, so you would copy, paste or upload the file into the web portal, you can use SDK as well, there are many languages, such as JAVA, .NET, Node or you can just make a RESTful HTTP call.

We're gonna use AWS CLI, the command would be "aws cloudformation create-stack", then you would specify stack name by using --stack-name and the name of the stack, which is myteststack in this example, then you would provide template by using --template-body and you would provide the file name, so file:// and you would see an extra slash here, that's just for the escape, that's just an escape symbol.

What the CloudFormation structure looks like. In our simple Bucket example, we only had resources, but there is also version, similarly to the SDK, you saw how you can specify the version, that's the best practice, because you want to know what version you're using and if there's a new version of the platform, you don't want your application and network structure to break, because of that.

Then there is a description, where you can put some metadata about your blueprint, such as just a text-based information, then there is resources, property of the CloudFormation blueprint, that's the most important part, that's where you would define your resources, you can also set up dependencies and you can also use some parameters, parameters on the same level as version, description and resources, you can define parameters, which layer you can use in resources, mappings allows you to map some of the parameters, that you will get during the creation of the stack to certain values, a good example would be different image IDs for different regions.

Image IDs, they're hard to remember, regions, they're easy to remember US East, US West, etc., so you don't need to remember image IDs and require them as parameters, you can set up the mapping from region to the image ID, you do it in mapping and then you can use the values in resources, for example, to create an EC2 resource in a particular region. Lastly, there is output, outputs allow you to a little bit minify, make it smaller, all the output or when you create this CloudFormation, because sometimes it has too much information.

0 comments