Lono is a tool that generates CloudFormation templates from smart ERB templates. With it, you can use variables and simplify managing your raw CloudFormation templates greatly.

I’ve covered using lono to generate templates in these posts:

When using lono the typical process looks like this:

  1. Update lono CloudFormation templates
  2. Run lono generate
  3. Construct a CloudFormation parameters file
  4. Run aws cloudformation create-stack

This is a manual and repetitive process which is subject to plenty of human errors along the way. I would forget step 2 and not run lono generate on accident. I would only realize my silly mistake after the stack errors and rolls back. For step 3, constructing the parameters file with CloudFormation’s verbose JSON array format is painstaking. For step 4, building up the long aws cloudformation create-stack command eats more precious time. This annoying manual process is a frustrating developer experience.

Lono also has param generation and CloudFormation lifecycle commands to remove this frustrating experience 😊 The official documentation for lono is at http://lono.cloud. I will give an introduction these lono commands in this post.

Review lono generate

First, you should read through the Generating Hundreds of CloudFormation Templates with Lono post to understand how lono generates CloudFormation templates. The generation phase is the first phase that lono automates. That post covers in detail how lono generates templates. For your convenience here is the diagram that shows the entire process including the generation process:

Introducing lono param

Next, the lono param subcommand is a tool that generates parameter files for the aws cloudformation CLI commands. It does this by reading an env file that simply has key=value pairs format. Using this simple format reduces JSON syntax errors.

For example, given a file at params/asg.txt:

Param1=1
# comments are fine
Param2=2 # comments can go after the line too
Param3=use_previous_value # treated specially

Running lono param generate will create a output/params/stag/asg.json file that contains:

[
  {
    "ParameterKey": "Param1",
    "ParameterValue": "1"
  },
  {
    "ParameterKey": "Param2",
    "ParameterValue": "2"
  },
  {
    "ParameterKey": "Param3",
    "UsePreviousValue": true
  }
]

Introducing lono cfn

The main command that ties everything together is lono cfn. It takes the manual steps I’ve mentioned at the beginning of this post:

  1. Update lono CloudFormation templates
  2. Run lono generate
  3. Construct a CloudFormation parameters file
  4. Run aws cloudformation create-stack

and simplifies it down to a single command!

The source code pretty much has these steps described. Using lono-cfn is extremely simple:

$ lono cfn create asg-$(date +%s) --template asg --param asg

Here I’m using the longer form and explicitly specifying the template and the param options. Let’s break down the command:

  • asg-$(date +%s): corresponds to the name of the stack being created
  • –template asg: corresponds to the output/asg.yml file, which is where lono generate writes the CloudFormation template to.
  • –param asg: to the output/params/stag/asg.yml file, which is where lono writes the parameters file to.

If the template and param name matches the stack name, then you can even get rid of those CLI options and simplify the command further. For example, both of these commands do the exact same thing.

$ lono cfn create asg --template asg --param asg
$ lono cfn create asg # shorter version

By using lono cfn you will never launch a CloudFormation stack with a stale generated template since lono cfn automatically calls lono generate. It also automatically builds the parameters files. More details about the tool can be found on the official documentation site: http://lono.cloud.

Summary

Lono is designed to simplify the workflow required to managed CloudFormation templates. With it creating CloudFormation stacks are much easier. Lono templates and parameter env-like files are extremely simple. The command lono cfn on top of this simplifies everything down to a single command. This eliminates manual and human error. I hope you enjoy this post and found find lono helpful!