In this post we will look at the basics of CloudFormation, what you need to know and how to get started in writing templates.
So you may be asking why I am writing a post about template basics when I have said I'll try not repeat information available on AWS.
Two reasons. Primarily to demystify the template and secondly to provide pointers to resources you might find useful as you improve your CloudFormation knowledge.
The AWS learn template basics post gives a very good walkthrough of how to build a template with details of all the components and options that make up a template. However, it can look daunting! I would suggest work out what the minimum is and then add components as you need them.
If you look at my 2 S3 templates you will see a major difference. The first "default" template that just creates a bucket based on what you want to call it is only 14 lines of code (18 with blank lines for readability). This will create a bucket, probably insecurely, but it will be a bucket. The second "secure" template is 146 lines of code. This creates a secure bucket, with a dedicated encryption key. It also uses some rules and parameters to configure the bucket and set standards.
So, don't get put off by over complicated templates as you're learning CloudFormation. Build up your own templates section at a time adding a new component or feature each time. This will not only be simpler and allow you to understand each component and the required structure but also produce less code failures.
If you want to understand Cloud Formation in more detail I'd suggest you take a look at the CloudFormation 101 workshop. It will walk you through the basic as well as more detailed components such as nested stacks and sharing values between stacks. It takes about 6 hours to do all components but a really good place to start to understand templates, deployment options and code.
The second resource, and this goes for anything in AWS, are the user documentation available at https://docs.aws.amazon.com/.
For CloudFormation this walks through the template structure, provides details about how to use and deploy templates, as well as providing code examples. However the most important piece for me is the "Template Reference" section. This provide a breakdown of each AWS resource you can create with all possible parameters, which are mandatory or optional, what format values need to be in and what calling the resource will return. This is extremely helpful when creating services that you are unfamiliar with or getting errors.