Custom Helpers

One of the best ways to keep your lono code readable is with custom helpers. The custom helpers are first class citizens and have access to the same context and variables as built-in DSL helpers.

Example Helper

You define helpers in the blueprint’s app/helpers folder as a module. The module name should be the camelized version of the file name. Here’s an example:

app/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 templates:

app/templates/demo.rb:

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

Pro tip: Use the <- and -> arrow keys to move back and forward.

Edit this page

See a typo or an error? You can improve this page. This website is available on GitHub and contributions are encouraged and welcomed. We love pull requests from you!