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:

template.yml:

Resources:
  Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType:
        Ref: InstanceType
      ImageId:
        Fn::FindInMap:
        - AmiMap
        - Ref: AWS::Region
        - Ami
      SecurityGroupIds:
      - Fn::GetAtt:
        - SecurityGroup
        - GroupId
      UserData:
        Fn::Base64: |-
          #!/bin/bash
          echo "hello world"
  SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      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",
  instance_type: ref("InstanceType"),
  image_id: find_in_map("AmiMap",ref("AWS::Region"),"Ami"),
  security_group_ids: [
    get_att("SecurityGroup","GroupId")
  ],
  user_data: base64("#!/bin/bash\necho \"hello world\"")
)
resource("SecurityGroup", "AWS::EC2::SecurityGroup",
  group_description: "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!