Skip to content

Latest commit

 

History

History
68 lines (59 loc) · 1.74 KB

File metadata and controls

68 lines (59 loc) · 1.74 KB
repo url homepage starredAt createdAt updatedAt language license branch stars isPublic isTemplate isArchived isFork hasReadMe refreshedAt description tags
trek10inc/cloudformation-schema-js-yaml
2025-01-08T05:59:41Z
2017-06-17T21:06:03Z
2025-01-08T05:59:41Z
JavaScript
NA
master
3
true
false
false
false
true
2025-02-25T19:51:19.042Z
Cloudformation custom class parser

Cloudformation Schema for use with js-yaml

Cloudformation supports custom yaml classes, e.g. !Ref, !Sub, !If, etc. Yaml parsers will choke on these custom classes unless the classes are specified. Use this library with js-yaml to parse cloudformation templates with these classes. The cloudformation classes are converted into objects that are similar to the non custom class syntax e.g. Ref, Fn::Sub, Fn::If

Usage

const yaml = require('js-yaml');
const schema = require('cloudformation-schema-js-yaml');
const fs = require('fs');

let file = fs.readFileSync('somefile.yaml');
let data = yaml.load(file, { schema: schema});

Example

sample.yaml

test:
  - !Ref someLogicalId
  - !Sub A string with a substitution ${someLogicalId}

Program extract

let file = fs.readFileSync('sample.yaml');
let data = yaml.load(file, { schema: schema});
console.log(data)
console.log('%j', data)

Output

{ test:
   [ Obj { Ref: 'someLogicalId' },
     Obj { 'Fn::Sub': 'A string with a substitution ${someLogicalId}' } ] }
{"test":[{"Ref":"someLogicalId"},{"Fn::Sub":"A string with a substitution ${someLogicalId}"}]}

Dependencies

None

Peer-dependencies

This this library is meant to be used with js-yaml it has a peer dependency of js-yaml

Tests

npm test