Custom Blueprint Helpers

Custom blueprint helpers are scoped to the blueprint. They live in the specific blueprint folder like app/blueprints/demo. For example:

app/blueprints/demo/helpers/custom_helper.rb

They are only available to the specific blueprint. They can override Lono core built-in helpers and project-level helpers.

Example Blueprint Helper

You define helpers in the blueprint’s helpers folder as a Ruby module. The module name should be the camelized version of the file name. Here’s an example where a helper is used to set default properties and remove the need to set the resource type:

app/blueprints/demo/helpers/ec2_helper.rb

module Ec2Helper
  def ec2_instance(logical_id, props={})
    default = {
      InstanceType: "t3.micro",
      ImageId: ref("AmiId"),
    }
    props.reverse_merge!(default)

    resource("Instance", "AWS::EC2::Instance", props)
  end

  def security_group(logical_id, props={})
    resource("SecurityGroup", "AWS::EC2::SecurityGroup", props)
  end
end

You can use the helper in your template:

app/blueprints/demo/template.rb

ec2_instance("Instance",
  SecurityGroupIds: [get_att("SecurityGroup.GroupId")]
)
security_group("SecurityGroup",
  GroupDescription: "demo security group",
)

Generate Helper

You can generate a starter helper module with:

lono new helper blueprint HELPER_NAME --blueprint BLUEPRINT # general form
lono new helper blueprint custom --blueprint demo
lono new helper blueprint --blueprint demo # the helper name defaults to custom

Example:

$ lono new helper blueprint --blueprint demo
=> Generating helper: custom
      create  app/blueprints/demo/helpers/custom_helper.rb
$