Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created December 28, 2017 00:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaskills/674d819f24f41ddb9664b0386d147ce0 to your computer and use it in GitHub Desktop.
Save metaskills/674d819f24f41ddb9664b0386d147ce0 to your computer and use it in GitHub Desktop.
Parse AWS SAM YAML Templates & Validate JSON Schema
#!/usr/bin/env ruby
require 'pp'
require 'json'
require 'yaml'
require 'open-uri'
require 'json-schema'
SCHEMA = begin
file = open('https://raw.githubusercontent.com/awslabs/goformation/master/schema/sam.schema.json')
JSON.parse File.read(file)
end
FILE = ARGV[0] || 'template.yaml'
PATH = File.expand_path(File.join(ENV['PWD'], FILE))
DATA = YAML.load(File.read(PATH))
begin
JSON::Validator.validate! SCHEMA, DATA
puts 'Valid!'
rescue JSON::Schema::ValidationError => e
puts e.message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment