Lono

Build History

Lono is a Cloud Formation Template ruby generator. Lono generates Cloud Formation templates based on ERB templates.

Usage


$ gem install lono
$ mkdir lono_project
$ lono init 

This sets up the basic lono project with an example template in source/app.json.erb.


$ lono generate

This generates the templates that have been defined in config/lono.rb.

The example starter config/lono.rb looks like this:

template "prod-api-app.json" do
  source "app.json.erb"
  variables(
    :env => 'prod',
    :app => 'api',
    :role => "app",
    :ami => "ami-123",
    :instance_type => "c1.xlarge",
    :port => "80",
    :high_threshold => "15",
    :high_periods => "4",
    :low_threshold => "5",
    :low_periods => "10",
    :max_size => "24",
    :min_size => "6",
    :down_adjustment => "-3",
    :up_adjustment => "3",
    :ssl_cert => "arn:aws:iam::12345:server-certificate/wildcard"
  )
end
template "prod-br-app.json" do
  source "app.json.erb"
  variables(
    :env => "prod",
    :app => 'br',
    :role => "app",
    :ami => "ami-456",
    :instance_type => "m1.medium",
    :port => "80",
    :high_threshold => "35",
    :high_periods => "4",
    :low_threshold => "20",
    :low_periods => "2",
    :max_size => "6",
    :min_size => "3",
    :down_adjustment => "-1",
    :up_adjustment => "2"
  )
end

The example ERB template file is in templates/app.json.erb.

User Data Helper

In the template files, there's user_data helper method available which can be used to include a user data script. The user data script should be in in the templates/user_data folder of the project. So:

  • user_data('bootstrap.sh.erb') -> templates/user_data/bootstrap.sh.erb
  • user_data('db.sh.erb') -> templates/user_data/db.sh.erb

Here's how you would call it in the template.

"UserData": {
  "Fn::Base64": {
    "Fn::Join": [
      "",
      [
        <%= user_data('bootstrap.sh.erb') %>
      ]
    ]
  }

Breaking up config/lono.rb

If you have a lot of templates, the config/lono.rb file can get unwieldy long. You can break up the lono.rb file and put template defintions in the config/lono directory. Any file in this directory will be automatically loaded.

An example is in the spec/project folder:

  • config/lono/api.rb

Generate

You can generate the CF templates by running:


$ lono generate

The lono init command also sets up guard-lono. Guard-lono continuously generates the cloud formation templates. Just run guard.


$ guard