Infrastructure as Code #2

Deploy adjustable Services via AWS: CloudFormation — Template Anatomy

David Krohn
globaldatanet
3 min readApr 27, 2018

--

In my last blog from this series I wrote about the CloudFormation service. You’ve learned how does CloudFormation operate and why you should use CloudFormation. This time I want to talk about the anatomy of an CloudFormation template.

Structure

A template is a simple „textfile“ written in YAML or JSON. You can define Resources, Parameters, Mappings, Conditions and Outputs to automate your infrastructure.

Notice if you work with the AWS CloudFormation Designer — AWS recommend that you don’t add # YAML comments to templates. All of your comments are lost if modifying your template with the Designer, because the Designer does not preserve those comments when converting the template to JSON.

Metadata

Metadata is an optional section. In the metadata section you could provide more details about the template (eg.: you could create a YAML objects to describe your EC2 instance which is created).

Parameters

Parameters is an optional section. With parameters you can specifies custom values that will be pass in to your template (eg. name or type of your Amazon EC2 instance). You can use parameters like variables to refer to them in the Resources and Output section.

Mappings

Mappings is an optional section. With Mappings you can define a value if a key matches to a similar set of named values (eg. if you want to create an EC2 instance with a specific AMI you’ll need Mappings, because in each region the AMI ID is different). A Full list of the Linux AMI IDs you can find here.

Conditions

Conditions is a optional section. With this Section you have the opportunity to control the behavior of your template depending on parameters (eg.: you have a template to create the infrastructure for your website. You want to have the same template for production and test, but for testing you might not require the same capacity that’s needed in the production infrastructure. Instead of having two templates you can use a condition which acts like a switch by controlling of a parameter.).

Resources

In addition to the information in which AWSTemplateFormatVersion the template is been written, resources is the only other required section. It declares the various services that you want to create in the stack (eg. Amazon S3 bucket). Every service requires a number of properties. Here is the link to the full list of the AWS Resource Type Reference.

Outputs

Outputs is an optional section. With this section you can display information of your stack direct in the AWS console, this outputs can be imported by another CloudFormation stack.

Limitations

While writing an template you have to pay attention to get not beyond the limit. Here are some limitations which you have to consider.

To get the full list of CloudFormation limitations follow this link.

globaldatanet is a technology services company that provides DevOps Automation on the Amazon Web Services (AWS) cloud. Deliver applications in a faster, innovative and secure way with our AWS DevOps Automation solutions using cutting-edge tools and DevOps methods. Whether you’re a startup, small-to-medium-sized enterprise (SME) or a large enterprise — we build individual DevOps solutions specific to your requirements.

--

--

David Krohn
globaldatanet

Cloud Solution Architect - #serverless #aws #devops