Cloudformation parameters

Advantages of using parameters in Cloudformation templates

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:

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.

However, an advantage of being able to customize our templates is to add environment variables, which facilitate the creation of our resources. It’s important to mention that they can be created in a generic way, therefore we can use them in any other environment we wish to create or replicate.

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:

  • You can have a maximum of 200 parameters in a AWS CloudFormation template.
  • Each parameter must have a logical name (also called logical ID), this has to be alphanumeric and unique among all logical names within the template.
  • Each parameter must be assigned an AWS CloudFormation compliant parameter type.
  • Each must be assigned a value at runtime in order to AWS CloudFormation to correctly provision the stack. If desired, a default value can be specified for AWS CloudFormation to use it unless another value is provided.
  • The parameters should be clear and referenced from the template itself.

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!

Related Post

Copyright ©2021 By Financial Solutions

Power by Cloudgenia

Contactar a un especialista

[contact-form-7 404 "Not Found"]