Lono CloudFormation Framework Introduction Part 4: Layering
In this post, we’ll cover Lono Layering. Layering can be used to build separate environments like a development and production environment. For example, the production environment might have different instance sizes. This can be accomplished with Lono layering.
Params
We covered Params configs in the previous article. Here it is again for review.
configs/demo/params
├── base.txt
├── development.txt
└── production.txt
Notice the base.txt
file. Lono layering will use the base.txt
and then “layers” the LONO_ENV specific file on top.
So:
LONO_ENV=development lono cfn deploy demo
Will use both:
params/base.txt
params/development.txt
And
LONO_ENV=production lono cfn deploy demo
Will use:
params/base.txt
params/production.txt
Examples with Values
params/base.txt:
InstanceType=t3.micro
params/development.txt:
# empty file
params/production.txt:
InstanceType=t3.large
In this case:
- LONO_ENV=development would use
InstanceType=t3.micro
from base.txt - LONO_ENV=production would use
InstanceType=t3.large
from production.txt
Variables
Here’s the variables structure:
configs/demo/variables
├── base.rb
├── development.rb
└── production.rb
Variables layering works the same as Params layering. Example:
base.rb:
@desc = "generic description from base.rb"
development.rb
@desc = "description from development.rb"
In this case:
LONO_ENV=development lono cfn deploy demo
Will use the @desc
value from development.rb
.
If the production.rb
does not exist or is empty, then:
LONO_ENV=production lono cfn deploy demo
Will use the @desc
value from base.rb
.
Demo
We’ll continue to use the EC2 instance example from previous posts to demonstrate Layering.
Add to and edit the configs
files with the values above. The source code is also here: tongueroo/lono-cloudformation-examples tutorial-4 configs
Confirm that the @desc
variable is being used in the template. It’ll look like this:
blueprints/demo/app/templates/demo.rb
description @desc
Then deploy both environments with different stack names using these commands:
LONO_ENV=development lono cfn deploy demo-development --blueprint demo
LONO_ENV=production lono cfn deploy demo-production --blueprint demo
Let’s check the CloudFormation console for demo-development
:
The demo-development
template:
Now check that the demo-production
stack values are different:
The demo-production
template:
Cleanup
Let’s destroy the resources so we do not get charged more money than we have to. This is simple.
LONO_ENV=development lono cfn delete demo-development --sure --no-wait
LONO_ENV=production lono cfn delete demo-production --sure --no-wait
Summary
This was a brief introduction to Layering support in Lono. Layering essentially merges multiple files to produce a final result. Layering is useful for building multiple environments like development and production. By using Layering, we stay DRY and use the same blueprints for different environments. In the next post of this series, we’ll cover one of my favorite commands: lono code convert.
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.