Registry / devops / cloudformation-schema-js-yaml

cloudformation-schema-js-yaml

JSON →
library2.0.2jsnpmunverified

js-yaml schema that adds CloudFormation custom YAML tags (!Ref, !Sub, !GetAtt, !If, etc.) enabling standard YAML parsers to handle CloudFormation templates. Current stable version 2.0.2, maintained since 2018, with low release cadence. It transforms tags into plain objects (e.g., !Ref logicalId -> {Ref: logicalId}) mimicking the long-form syntax. Differentiator: lightweight, no additional dependencies beyond js-yaml peer dep, and supports all core CloudFormation intrinsic functions.

npm install cloudformation-schema-js-yaml
INSTALL
IMPORT
SIG · CLOUDFORMATION-SCH
C
cloudformation-schema-js-yaml
devopsjavascriptv2.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

schema
const schema = require('cloudformation-schema-js-yaml');
const schema = require('cloudformation-schema-js-yaml').default;
Package exports a single schema object via module.exports, no default export.
schema
import schema from 'cloudformation-schema-js-yaml';
import { schema } from 'cloudformation-schema-js-yaml';
In ESM, default import works because the module uses module.exports. Named import fails.
yaml
const yaml = require('js-yaml');
import yaml from 'js-yaml'; // works but CJS require is more common in Node
js-yaml is a peer dependency, version ^4.1.0. Both CJS and ESM work, but CJS is traditional.

Read a CloudFormation YAML file and parse it using js-yaml with the custom schema, outputting the resulting object as JSON.

const fs = require('fs'); const yaml = require('js-yaml'); const schema = require('cloudformation-schema-js-yaml'); const file = fs.readFileSync('template.yaml', 'utf8'); const data = yaml.load(file, { schema }); console.log(JSON.stringify(data, null, 2));
Debug
Known issues
breakingVersion 2.x uses js-yaml v4 which changes the API: safeLoad -> load, safeLoadAll -> loadAll.
fix
Update code to use yaml.load() instead of yaml.safeLoad().
affects: >=2.0.0
deprecatedjs-yaml v4 deprecated safeLoad and safeLoadAll; use load and loadAll with options.
fix
Use yaml.load(content, { schema }) instead of yaml.safeLoad(content, { schema }).
affects: *
gotchaThe schema only converts tags to objects; nested tags in strings (e.g., !Sub) may not be parsed if they appear inside other tags.
fix
Ensure tags are represented as YAML tags, not embedded in strings.
affects: all
gotchajs-yaml@4 throws on duplicate keys by default; CloudFormation templates sometimes have overlapping mappings.
fix
Use yaml.load(content, { schema, uniqueKeys: false }) to allow duplicate keys.
affects: >=2.0.0
deprecatedThe package has no TypeScript types; you may need to declare a module.
fix
Create a declaration file: declare module 'cloudformation-schema-js-yaml' { const schema: any; export default schema; }
affects: all
Errors
Common errors & fixes
unknown tag !Ref
js-yaml loaded without the CloudFormation schema, so custom tags are not recognized.
fix
Pass the schema option: yaml.load(content, { schema: require('cloudformation-schema-js-yaml') }).
TypeError: schema is not a function
Importing the package incorrectly, e.g., using require('cloudformation-schema-js-yaml').default which is undefined.
fix
Use correct import: const schema = require('cloudformation-schema-js-yaml');
Cannot find module 'cloudformation-schema-js-yaml'
Package not installed or missing from node_modules.
fix
Run 'npm install cloudformation-schema-js-yaml' and also ensure js-yaml is installed ('npm install js-yaml').
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
js-yamloptionalpeer dependency required to use this schema
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
cloudformation-schema-js-yaml — npm install cloudformation-schema-js-yaml · libregistry