DSL

Lono provides the ability write your CloudFormation template with a DSL. Here’s an example of what the DSL looks like.

app/templates/demo.rb:

description "Demo stack"

parameter(:instance_type, "t3.micro")

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

resource(:instance, "AWS::EC2::Instance",
  instance_type: ref(:instance_type),
  image_id: find_in_map(:ami_map, ref("AWS::Region"), :ami),
  security_group_ids: [get_att("security_group.group_id")],
  user_data: base64(user_data("bootstrap.sh"))
)
resource(:security_group, "AWS::EC2::SecurityGroup",
  group_description: "demo security group",
)

output(:instance)
output(:security_group, get_att("security_group.group_id"))

Here are the top-level DSL methods.

Method Description
Format Version The optional AWSTemplateFormatVersion section identifies the capabilities of the template.
Condition The optional Conditions section contains statements that define the circumstances under which entities are created or configured.
Description The optional Description section enables you to include comments about your template. The Description must follow the AWSTemplateFormatVersion section.
Mapping The optional Mappings section matches a key to a corresponding set of named values.
Metadata The optional Mappings section matches a key to a corresponding set of named values.
Output The optional Outputs section declares output values shown in the CloudFormation outputs console.
Parameter Use the optional Parameters section to customize your templates. Parameters enable you to input custom values to your template each time you create or update a stack.
Resource The required Resources section declares the AWS resources that you want to include in the stack, such as an Amazon EC2 instance or an Amazon S3 bucket.
Section General way to add a section to the generated CloudFormation template.
Transform The optional Transform section specifies one or more macros that AWS CloudFormation uses to process your template.

The main methods correspond to sections of the CloudFormation anatomy sections.

The DSL provides full access to creating custom CloudFormation stacks and AWS resources. It is also easy wrap the DSL with your own Helpers. This helps you keep your code concise and more readable.

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!