Walkthrough

Here’s a brief walkthrough of how lono works.

  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 that includes 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",
  instance_type: ref("InstanceType"),
  image_id: find_in_map("AmiMap", ref("AWS::Region"), :ami),
  security_group_ids: [get_att("SecurityGroup.GroupId")],
  user_data: base64(user_data("bootstrap.sh"))
)
resource("SecurityGroup", "AWS::EC2::SecurityGroup",
  group_description: "demo security group",
)

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

2. Generate the Template

When you run:

lono generate

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, then you can deploy them with:

lono cfn deploy demo

Note, the lono cfn deploy command automatically calls lono generate so you don’t have to worry about regenerating the template. You can check on the stack on 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!