Skip to the content.

Helper Functions

Templates rendered with Handlebars or EJS gain a set of extra helpers on top of any that are built into the respective Template Rendering Engine.

In addition to built in helpers, you can define your own helper functions in JavaScript. Crustomize will look for a folder in the working directory called crustomize_helpers and import all .js files. Any exported function is now available as a helper. You can override the folder location using the --helpers/-H switch, the helpers: key in a .crustomizerc file, or the CRUSTOMIZE_HELPERS environment variable.

All three sources accept a colon-separated list of paths, and each path can be either a local file/folder or an s3://bucket/prefix URL — see Custom helpers for details.

A helper function is a function that receives a few context parameters and returns a helper function. Read more about custom helpers here.

indent

Indents a string by a number of spaces. Useful when reading other files and merging them into a YAML template so indentation stays correct.

Example

{{indent (getFile "policy.json") 4}}

toYaml

Converts an object to YAML

Example

{{toYaml values}}

quote

Wraps a value in double quotes.

Example

{{quote env.REGION}}

trunc

Truncates a string to a maximum length.

Example

{{trunc stackName 12}}

toBase64

Encodes a string as base64.

Example

{{toBase64 "foo"}}

getFile

Reads a file relative to the manifest and returns its contents.

Example

{{getFile "userdata.sh"}}

fileToBase64

Reads a file relative to the manifest and returns its base64 encoded contents.

Example

{{fileToBase64 "userdata.sh"}}

lookupCfOutput

Retrieves an output from an existing CloudFormation stack.

Example

{{lookupCfOutput "network", "VpcId"}}

getParameter

Fetches a parameter from AWS Systems Manager Parameter Store.

Example

{{getParameter "/my/param"}}

valueOrDefault

Returns a value or a provided default.

Example

{{valueOrDefault env.IMAGE_TAG "latest"}}