Lono Code Convert

Lono features a powerful DSL to build CloudFormation templates. The Lono DSL builds on top of the CloudFormation declarative nature and allows you to deliver Infrastructure as Code. The Lono DSL results in more maintainable code. Most CloudFormation templates in the wild are written in JSON or YAML though.

The lono code convert command allows you to take JSON or YAML templates and convert it to the Lono Ruby DSL code. The conversion process saves you engineering time writing it yourself.

Usage: lono code convert

The lono code convert commmand will convert snippets of template code to Ruby code. Here’s an example:


    Type: AWS::EC2::Instance
        Ref: InstanceType
        - AmiMap
        - Ref: AWS::Region
        - Ami
      - Fn::GetAtt:
        - SecurityGroup
        - GroupId
        Fn::Base64: |-
          echo "hello world"
    Type: AWS::EC2::SecurityGroup
      GroupDescription: demo security group

Here’s an example running convert on the template.yml:

$ lono code convert template.yml > template.rb
INFO: The ruby syntax is valid
INFO: Translated ruby code below:

$ ruby -c template.rb
Syntax OK

The INFO messages are written to stderr and the Ruby code output is written to stdout. We’re using bash redirection write to template.rb. Here’s what template.rb looks like

resource("Instance", "AWS::EC2::Instance",
  InstanceType: ref("InstanceType"),
  ImageId: find_in_map("AmiMap",ref("AWS::Region"),"Ami"),
  SecurityGroupIds: [
  UserData: base64("#!/bin/bash\necho \"hello world\"")
resource("SecurityGroup", "AWS::EC2::SecurityGroup",
  GroupDescription: "demo security group"

The convert command saves a ton of time.

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!