# Custom Parameter Resolvers

You can provide custom parameter resolvers by placing .js files to resolvers directory.

# Custom Resolver File

The custom resolver files must be plain javascript files. Each custom resolver is defined in its own file by exporting the properties documented below. You can use all JavaScript language features available in Node.js version 14.4.0.

# name

  • Type: string, function
  • Required: yes
  • Requirements:
    • Must match regex /^[a-zA-Z]+[a-zA-Z0-9-_]*$/

Name of the resolver that is used to refer to the resolver from stack configuration files. Can be either a string or a function that returns a string. The function must not be asynchronous.

# init

  • Type: function
  • Required: yes

A function that initializes the resolver with properties given in a stack configuration file. The function can be either normal or async, and must return an instantiated resolver object.

# schema

  • Type: function
  • Required: no

An optional function that returns a Joi schema that is used to validate configuration provided for the resolver from stack configuration files. It takes two arguments: Joi instance and Joi object schema. The former can be used to create new validation constraints and the latter is a pre-initialized object schema that you can modify to provide the validation schema for your resolver. You can return the pre-initialized schema from the schema function, or you can use the Joi root instance to create a completely new schema.

# Resolver Object

Here are properties for the resolver object:

# resolve

  • Type: function
  • Required: yes

Function that resolves the actual parameter value. The resolved value can be of any type, and is converted to a string before it is passed to CloudFormation. If the value is an array, it is converted to a string by joining its values with comma.

The resolve function is invoked with a single argument that contains the following properties:

# ctx

The command context object.

# stack

The current stack object.

# parameterName

The name of parameter.

# listParameterIndex

If the parameter is of type List<> or CommaDelimitedList, this will hold the index of value in the list.

# logger

Logger.

# confidential

  • Type: boolean, function
  • Required: no
  • Default value: false
  • Requirements:
    • If a function is used, it must not be asynchronous

A boolean or a function that returns a boolean value determining if the resolved parameter value should be concealed from log messages.

confidential property in a stack configuration file takes precedence over this value.

# dependencies

  • Type: string[], function
  • Required: no
  • Default value: []
  • Requirements:
    • If a function is used, it must not be asynchronous

A list of stack paths or a function that returns a list of stack paths of the stacks that the resolver depends on.

# iamRoleArns

  • Type: string[], function
  • Required: no
  • Default value: []
  • Requirements:
    • If a function is used, it must not be asynchronous

A list of IAM role ARNs or a function that returns a list of IAM role ARNs needed to resolve the value.

# Example

A custom resolver that converts value given in the resolver configuration to uppercase. The resolver schema requires that in stack configuration file where the resolver is used, the resolver configuration must contain a value property of type string and that its value must not have more than 50 characters.

module.exports = {
  name: "uppercase",
  schema: (joi, schema) => {
    return schema.keys({
      value: joi.string().max(50).required()
    })
  },
  init: (props) => {
    return {
      confidential: true,
      dependencies: () => [],
      iamRoleArns: [],
      resolve: (input) => {
        input.logger.debug("Execute uppercase!");
        input.logger.debug(`Resolve value for parameter '${input.parameterName}'`);
        return props.value.toUpperCase();
      }
    }
  }
};

This resolver can then be used in stack configuration file like so:

parameters:
  MyParameter:
    resolver: uppercase
    value: hello

See Also

Last Updated: 6/21/2020, 7:50:09 PM