Lono CloudFormation Framework Introduction Part 6: Lono Seed
When working with CloudFormation, you usually configure parameters for the template. The lono seed command helps with this step by generating a starter param file. It evaluates the template itself to generate the starter example values. We’ll use the demo blueprint we created in Lono CloudFormation Framework Introduction Part 1: EC2 Instance.
How It Works
Just run lono seed with the blueprint name.
lono seed BLUEPRINT
Here’s an example with output:
$ lono seed demo
Creating starter config files for demo
Generating CloudFormation templates for blueprint demo:
output/demo/templates/demo.yml
create configs/demo/params/development.txt
$
Let’s look at the contents:
# InstanceType=t3.micro
In this simple demo example, there is only 1 parameter to configure. For templates with several parameters, the lono seed command is a larger time saver.
Notice that the structure also separates configs from blueprints. This allows us to reuse blueprints and follow the DRY principle. For example, the structure allows us to use the same CloudFormation code to create different environments. To generate starter seed files for different environments set LONO_ENV
. Example:
$ LONO_ENV=production lono seed demo
Creating starter config files for demo
Generating CloudFormation templates for blueprint demo:
output/demo/templates/demo.yml
create configs/demo/params/production.txt
$
That produces configs/demo/params/production.txt
. We can use different parameters for the development vs production environments.
How Starter Values Are Determined
Interestingly, the starter values are derived from the template definition itself. The parameter Description
is used. Anything after “Example: “ or “IE: “ is extracted and used as the value. Example:
app/templates/demo.rb:
parameter("Vpc", Description: "Virtual Private Network VPC. Example: vpc-111")
This produces:
configs/demo/params/development.txt
Vpc=vpc-111
Variables Seed Files
For our demo blueprint, lono seed
does not create starter configs/demo/variables
files. Some blueprints will also generate starter variables config files.
Starter variables cannot be inferred from the CloudFormation template themselves, though. So the blueprint must be authored to support starter variables files. The blueprint tells lono seed
how to generate starter variables files with a seeds/configs.rb
file. Here’s the interface for the configs.rb
:
class Lono::Seed::Configs < Lono::Seed::Base
def variables
<<~EOL
@somevar = "my value"
EOL
end
end
The class must be named Lono::Seed::Configs
and inherit from Lono::Seed::Base
. The variables
method returns a String. The String is used for the contents of configs/demo/variables/development.rb
. If we add the example above and run lono seed
again.
LONO_ENV=development lono seed demo
LONO_ENV=production lono seed demo
This time it creates the starter variables files also.
$ tree configs/demo/
configs/demo/
├── params
│ ├── development.txt
│ └── production.txt
└── variables
├── development.rb
└── production.rb
$
The contents of configs/demo/variables/development.rb:
@somevar = "my value"
Summary
We covered lono seed in detail in this post. It provides a quick way to generate starter configs for your blueprints. There’s more info on lono seed on the docs. In the next post, we’ll cover variables and loops.
Lono Introduction Series
Thanks for reading this far. If you found this article useful, I'd really appreciate it if you share this article so others can find it too! Thanks 😁 Also follow me on Twitter.
Got questions? Check out BoltOps.
You might also like
More tools:
-
Kubes
Kubes: Kubernetes Deployment Tool
Kubes is a Kubernetes Deployment Tool. It builds the docker image, creates the Kubernetes YAML, and runs kubectl apply. It automates the deployment process and saves you precious finger-typing energy.
-
Jets
Jets: The Ruby Serverless Framework
Ruby on Jets allows you to create and deploy serverless services with ease, and to seamlessly glue AWS services together with the most beautiful dynamic language: Ruby. It includes everything you need to build an API and deploy it to AWS Lambda. Jets leverages the power of Ruby to make serverless joyful for everyone.
-
Lono
Lono: The CloudFormation Framework
Building infrastructure-as-code is challenging. Lono makes it much easier and fun. It includes everything you need to manage and deploy infrastructure-as-code.