Registry / devops / serverless-plugin-utils

serverless-plugin-utils

JSON →
library0.2.0jsnpmunverified

serverless-plugin-utils is a collection of essential utilities designed to augment the Serverless Framework's configuration capabilities. Currently stable at version 0.2.0, it provides a set of helper functions primarily consumed directly within `serverless.yml` files, enhancing the declarative power of serverless configurations. These utilities facilitate common operations such as string manipulation (lowercase, uppercase, capitalize, split, join), conditional logic (ternary, switch statements), and other dynamic value resolutions, which are frequently encountered when defining resources, environment variables, or other service properties. It allows developers to create more dynamic and adaptive Serverless configurations without resorting to external scripting or complex custom logic, streamlining tasks like enforcing S3 bucket naming conventions or dynamic domain construction. The package is typically installed as a development dependency and integrates seamlessly into the Serverless Framework's variable resolution system.

npm install serverless-plugin-utils
INSTALL
IMPORT
SIG · SERVERLESS-PLUGIN-
S
serverless-plugin-utils
devopsjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lower
${fn:lower('YourString')}
import { lower } from 'serverless-plugin-utils'
Utility functions are exposed via the Serverless Framework's variable system, not direct JavaScript module imports. This is the correct YAML syntax.
join
${fn:join(',', ['item1', 'item2'])}
require('serverless-plugin-utils').join()
Access utility functions directly in serverless.yml using the specified variable syntax. Direct programmatic JavaScript access to these specific utilities is not the intended use case for end-users.
ternary
${fn:ternary(condition, 'trueValue', 'falseValue')}
const ternary = require('serverless-plugin-utils').ternary;
The primary interface for these utilities is through Serverless YAML variables. The plugin itself is loaded by the Serverless Framework at runtime.

This quickstart demonstrates how to integrate `serverless-plugin-utils` into your `serverless.yml` and use its functions to dynamically set environment variables for a Lambda function. It showcases `lower`, `capitalize`, `join`, and `ternary` utilities.

service: my-serverless-app frameworkVersion: '3' plugins: - serverless-plugin-utils provider: name: aws runtime: nodejs18.x stage: ${opt:stage, 'dev'} environment: SERVICE_NAME_LOWER: ${fn:lower(self:service)} DEPLOY_STAGE_CAPITALIZED: ${fn:capitalize(self:provider.stage)} DYNAMIC_BUCKET_NAME: ${fn:join('-', [self:service, ${fn:lower(self:provider.stage)}, 'resources'])} IS_PROD: ${fn:ternary(${self:provider.stage} == 'prod', true, false)} functions: hello: handler: handler.hello events: - http: path: hello method: get # handler.ts example (not directly importing utils, but using env vars) // export const hello = async (event: any) => { // const serviceName = process.env.SERVICE_NAME_LOWER ?? ''; // const stage = process.env.DEPLOY_STAGE_CAPITALIZED ?? ''; // const isProd = process.env.IS_PROD === 'true'; // return { // statusCode: 200, // body: JSON.stringify({ // message: `Hello from ${serviceName} in ${stage} (Prod: ${isProd})!`, // input: event, // }), // }; // };
Debug
Known issues
gotchaThis package is at a low version (0.2.0), which historically indicates it may be in early development. While it appears stable for its advertised functionality, anticipate potential breaking changes in minor or patch versions if the project becomes more actively developed, or if Serverless Framework itself introduces breaking changes that impact plugin compatibility.
fix
Always pin to an exact version (`~0.2.0` or `0.2.0`) and test thoroughly before upgrading. Review the plugin's GitHub repository for any recent activity or changelogs.
affects: >=0.0.1
gotchaThe utilities provided by this plugin are primarily designed for use within `serverless.yml` via the Serverless Framework's variable system (e.g., `${fn:lower('...')}`). Attempting to `import` or `require` these utility functions directly into your JavaScript/TypeScript Lambda code will not work as expected, as they are not exposed as standard module exports for programmatic consumption.
fix
Use the documented Serverless variable syntax within your `serverless.yml` configuration. If you need similar logic in your Lambda code, implement it directly in JavaScript/TypeScript using standard library functions.
affects: >=0.0.1
gotchaThis plugin registers its utilities under a specific variable namespace (often `fn:` or implicit). Ensure that your `serverless.yml` file correctly lists `serverless-plugin-utils` in the `plugins` section. Forgetting to register the plugin or using an incorrect variable prefix will lead to 'variable not found' errors.
fix
Verify that `plugins: - serverless-plugin-utils` is present in your `serverless.yml`. Refer to the plugin's documentation for the exact variable prefix if it deviates from the common `fn:`.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot resolve variable at 'provider.environment.MY_VAR': Variable 'fn:lower' not found.
The `serverless-plugin-utils` plugin has not been correctly registered in your `serverless.yml` or the Serverless Framework version is incompatible.
fix
Ensure `serverless-plugin-utils` is listed under the `plugins` section in your `serverless.yml`:
```yaml
plugins:
  - serverless-plugin-utils
```
Also, check the compatibility of the plugin with your Serverless Framework version.
YAMLException: bad indentation of a mapping entry
Incorrect YAML syntax when defining or calling a utility function within `serverless.yml`.
fix
YAML is whitespace-sensitive. Carefully review the indentation and spacing of your `serverless.yml` file, especially around utility function calls and their arguments. Use a YAML linter if available.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
serverlessrequiredThis package is a plugin for the Serverless Framework and requires it to function. It should be listed as a peer dependency.
Agent activity
8 hits · last 30 days
node
8
Resources
serverless-plugin-utils — npm install serverless-plugin-utils · libregistry