Walkthrough

Here’s a walkthrough of how lono works that’s more detailed than the Quick Start.

  1. You define blueprints that include templates written in a DSL
  2. You generate the templates and verify that they look good
  3. You deploy the blueprint’s template with lono cfn deploy

1. Demo Template DSL

The lono new command creates a lono project structure. Then you use the lono blueprint new to generate a demo blueprint. That demo blueprint looks something like this:

app/templates/demo.rb:

description "Demo stack"

parameter("InstanceType", "t3.micro")

mapping("AmiMap",
  "us-east-1": { Ami: "ami-0de53d8956e8dcf80" },
  "us-west-2": { Ami: "ami-061392db613a6357b" }
)

resource("Instance", "AWS::EC2::Instance",
  InstanceType: ref("InstanceType"),
  ImageId: find_in_map("AmiMap", ref("AWS::Region"), "Ami"),
  SecurityGroupIds: [get_att("SecurityGroup.GroupId")],
  UserData: base64(user_data("bootstrap.sh"))
)
resource("SecurityGroup", "AWS::EC2::SecurityGroup",
  GroupDescription: "demo security group",
)

output("Instance")
output("SecurityGroup", get_att("SecurityGroup.GroupId"))

2. Generate the Template

You can optionally use lono generate to generate the templates.

lono generate demo

It’ll generates a CloudFormation template from the DSL and writes it to output/demo/templates/demo.yml:

Description: Demo stack
Parameters:
  InstanceType:
    Default: t3.micro
    Type: String
Mappings:
  AmiMap:
    us-east-1:
      Ami: ami-0de53d8956e8dcf80
    us-west-2:
      Ami: ami-061392db613a6357b
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 hi
  SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: demo security group
Outputs:
  Instance:
    Value:
      Ref: Instance
  SecurityGroup:
    Value:
      Fn::GetAtt:
      - SecurityGroup
      - GroupId

3. Deploy the Blueprint’s Template

When your templates look good, you then use lono cfn deploy to launch the stack:

lono cfn deploy demo

You can check on the stack in the AWS CloudFormation console:

Stack Created

That’s it! Hopefully that brief walkthrough helps. 😄

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!