Created
February 9, 2017 21:18
-
-
Save olegch/37212ba350cabca921fd3109df2d1981 to your computer and use it in GitHub Desktop.
Loading a CloudFormation yaml file with custom tags with js-yaml in node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var fs = require('fs'); | |
var yaml = require('js-yaml'); | |
var inputStr = fs.readFileSync('../../out/aws-cloud-formation-template-1.template', {encoding: 'UTF-8'}); | |
var CF_SCHEMA = yaml.Schema.create([ | |
new yaml.Type('!Ref', { kind: 'scalar', construct: function (data) { return { 'Ref': data }; } }), | |
new yaml.Type('!Equals', { kind: 'sequence', construct: function (data) { return { 'Fn::Equals': data }; } }), | |
new yaml.Type('!Not', { kind: 'sequence', construct: function (data) { return { 'Fn::Not': data }; } }), | |
new yaml.Type('!Sub', { kind: 'scalar', construct: function (data) { return { 'Fn::Sub': data }; } }), | |
new yaml.Type('!If', { kind: 'sequence', construct: function (data) { return { 'Fn::If': data }; } }), | |
new yaml.Type('!Join', { kind: 'sequence', construct: function (data) { return { 'Fn::Join': data }; } }), | |
new yaml.Type('!Select', { kind: 'sequence', construct: function (data) { return { 'Fn::Select': data }; } }), | |
new yaml.Type('!FindInMap', { kind: 'sequence', construct: function (data) { return { 'Fn::FindInMap': data }; } }), | |
new yaml.Type('!GetAtt', { kind: 'sequence', construct: function (data) { return { 'Fn::GetAtt': data }; } }), | |
new yaml.Type('!GetAZs', { kind: 'scalar', construct: function (data) { return { 'Fn::GetAZs': data }; } }), | |
new yaml.Type('!Base64', { kind: 'mapping', construct: function (data) { return { 'Fn::Base64': data }; } }) | |
]); | |
var input = yaml.safeLoad(inputStr, { schema: CF_SCHEMA }); | |
console.log(yaml.safeDump(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment