This plugin for the Serverless Framework enhances `serverless.yml` files by automatically converting a custom `#{Variable}` syntax into AWS CloudFormation `Fn::Sub` functions. It supports a wide range of CloudFormation variables, including template parameters, resource logical IDs, resource attributes, pseudo parameters (e.g., `AWS::Region`), literal variables, and key-value map `Fn::Sub` functions. The plugin operates during the `package` command, executing its transformations after Serverless variables (`${self:variable}`) are resolved but before the CloudFormation template is packaged for deployment. A key feature is its ability to automatically wrap strings with `Fn::Sub` unless `Fn::Sub` is already explicitly defined in the parent YAML node, providing flexibility for complex scenarios. The current stable version is 0.2.1, released in late 2023, reflecting a deliberate, slower release cadence focused on stability and specific bug fixes. Its primary differentiator is the transparent and generic conversion of `#{...}` syntax across the entire CloudFormation template portion of `serverless.yml`, simplifying complex CloudFormation variable usage without extensive manual `Fn::Sub` declarations.
npm install serverless-cloudformation-sub-variablesVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to install the plugin via npm and configure it in `serverless.yml` to automatically convert `#{...}` syntax into `Fn::Sub` for CloudFormation resources and outputs, including pseudo-parameters and resource references.
Understand the processing order: Serverless variables (`${...}`) are resolved first by the Serverless Framework itself. Afterwards, this plugin converts `#{...}` into CloudFormation `Fn::Sub` functions. Design your `serverless.yml` accordingly, using `${...}` for Serverless-specific variables and `#{...}` for CloudFormation intrinsic variables.Upgrade to version 0.2.1 or newer to benefit from the fix that gracefully handles `null` or `undefined` values by skipping their processing. If upgrading is not immediately possible, ensure all values targeted for `Fn::Sub` conversion are explicitly defined and not `null` or `undefined`.
Design your CloudFormation templates knowing this behavior. If you want to declare a key-value map for `Fn::Sub` (e.g., `Fn::Sub: [ 'string', { key: value } ]`), explicitly use `Fn::Sub`. For simpler strings containing `#{...}` without a parent `Fn::Sub`, the plugin will automatically add the wrapper.Double-check the exact spelling and casing of your CloudFormation logical IDs, pseudo-parameters, or attributes (e.g., `#{MyResource.Arn}`). Ensure the resource or parameter you are referencing actually exists in your template or is a valid AWS pseudo-parameter. The plugin only converts `#{...}` to `${...}` for CloudFormation, so the underlying CloudFormation validation still applies.Verify that `serverless-cloudformation-sub-variables` is correctly spelled in your `plugins` section of `serverless.yml`. Confirm that the package is installed in your project's `node_modules` by running `npm install serverless-cloudformation-sub-variables` or `yarn add serverless-cloudformation-sub-variables`.
Review your `serverless.yml` for correct YAML syntax, paying close attention to indentation, colons, and hyphens. Use a YAML linter or an IDE with good YAML support to help identify syntax errors. Ensure that string values containing special characters or multiline content are properly quoted if necessary.