Parameters in CloudFormation Template

Ashvini Praisoody
2 min readApr 29, 2021

Being a optional section in the cloudFormation Template, Parameters facilitates in adding custom values to our templates. This blog not only covers the basic concepts of parameters, But also it gives a brief idea of storing and accessing the values of the parameters.

Let’s see how to add the parameters to our template, how to store the values of these parameters in a json file and finally how we can access these values and merge it to our template.

Let’s get started…

Source : AWS Infrastructure as Code — September 2016 Webinar Series

Now let’s take a look at a sample parameter added to a template and understand.

AWS Cloud Formation is a service that assists you in modeling and setting up your Amazon Web Services tools so you can spend less time in managing them and more time in working on your AWS-based applications. In an AWS Cloud Formation template, we can have up to 200 parameters.

Each parameter must have following components.

1. Logical Name

Each parameter must have its own logical name (logical ID), which must be alphanumeric and distinct from the other logical names in the template.

2. Type

It is compulsory to use parameter type. We can use simple parameter types like String, int or we can use AWS parameter types.

3. Value

A value must be assigned to each parameter we specify in the template. we can either set a default value or provide it during the deployment .we usually do this with a CI script.

These parameters can be given a default value within the cloudFormation Template or we can also give that while deploying the stacks.

aws cloudformation create-stack --stack-name myteststack --template-body file://sampletemplate.json --parameters ParameterKey=KeyPairName,ParameterValue=TestKey ParameterKey=SubnetIDs,ParameterValue=SubnetID1\\,SubnetID2

The above example has the Parameter Key and the associated value to be given.

Also we can generate a seperate file that holds all the key value pairs for parameters and pass the file in the create stack command.

Imagine you have the parameters within a json file names parameters.json. You then read the values of the parameters using many methods like jq. After passing the value to a simple variable like $params, we can then run the create stack command as below.

aws cloudformation create-stack --stack-name myteststack --template-body file://sampletemplate.json --parameters $params

This a good way to manage the parameters of the templates. Hope you got a clear understanding of the parameters. Follow for more updates on aws.

--

--

Ashvini Praisoody
0 Followers

Undergraduate SLIIT | Intern Software Engineer WSO2