By Josue Armando Vazquez, Infrastructure DevOps at Financial Solutions
AWS CloudFormation is a service that help us to create AWS resources in a faster way, so that infrastructure’s deployment time is considerably reduced.
There are several default templates created by Amazon that are used to replicate complex environments for development, either in pre or production, they can be similar or almost the same simply by scaling the resources. To view more of these example templates, please review the following link: https://amzn.to/2SfY3Vm
The usage of templates will depend on our requirements, it’s not mandatory to use them, since you can create your own from scratch using YAML or JSON formats.
Some of the advantages of using default templates are:
· It will take less time than creating a template from scratch, since some of them couldn’t be parameterized with the configurations we need at that moment, and we would have to invest some time in modifying them.
· Since we won’t need to modify the configurations, which come by default from the resources of these templates, the deployment is fast and in a matter of minutes we will have our service infrastructure deployed, considering that each service has its own creations time.
To create our environment variables, it’s necessary that our template includes the parameters section as shown below:
These would be the requirements to be considered when using the parameters:
That way it would become a “custom” section and should look as follows:
In YAML format:
In JSON format:
This way we can reuse our templates as many times as we want and when we run them, CloudFormation will identify these variables by requesting them in step 2.
In order to use these variables or parameters throughout our template, it’s necessary to use the reserved word “REF”. This way, CloudFormation will use use that parameter.
Here is an example of how it would be in JSON or YAML format:
This image shows how it’s included in the parameter section:
This one shows what the reference to the variable looks like in JSON format:
And this one shows us what the reference to the variable looks like in YAML format:
Customizing our CloudFormation templates is very important, because by doing it this way, we can have well organized the values we’ll need along our YAML or JSON script. Also, it allows us to reuse our templates, without the need to edit those files.
Using CloudFormation when creating or cloning resources saves us time, work and configurations.
Let me know if it worked for you and if you would like any other tutorials!