Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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