Nested Stack Support

Lono provides helper methods to help work with nested CloudFormation templates.

Helper Description
template_s3_path(name) This is the s3 path where template gets uploaded to s3. This required for the TemplateURL property of an AWS::CloudFormation::Stack child stack resource.
template_params(name) This returns an Array of the parameter values. This is useful in a parent template if you are using nested templates. You can use this to grab the params values from child templates and specify the parameters within the parent template to other child templates.

The template_s3_path helper

Instead of hard-coding the s3 bucket and path name in your parent stack you can use this helper to reference it from code. You use it in your app/templates/parent.yml like so:

<%= template_s3_path("ChildTemplate") %>

This produces the url in your output/templates/parent.yml:

Note that the LONO_ENV is added to the final s3 path in case you are using the same s3 bucket for multiple environments.

The template_params helper

Typically child templates in a nested stack setup use parameters specified in the parent stack template definition. The template_params helper allows you to grab the parameter values in the params files and inject them into the parent template. This allows you to launch the child template as separate stand-alone stacks using the runtime params values or as an embedded child stack using those same parameter values. Example:


    Type: AWS::CloudFormation::Stack
      TemplateURL: <%= template_s3_path("network") %>
      <% template_params("network").each do |key, value| %>
        <%= key %>: <%= value %>
      <% end %>


    Type: AWS::EC2::VPC



Note you might want to put inline parameter values in the parent template at the bottom after the template_params loop, so it is clear what the final values parameters being passed into the child template are.

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!