Skip to content

Instantly share code, notes, and snippets.

@mlafeldt
Created August 14, 2013 15:08
Show Gist options
  • Select an option

  • Save mlafeldt/6231957 to your computer and use it in GitHub Desktop.

Select an option

Save mlafeldt/6231957 to your computer and use it in GitHub Desktop.
Validate CloudFormation templates with aws-sdk
require 'aws-sdk'
def validate_template(body)
cfn = AWS::CloudFormation.new
cfn.validate_template(body)
end
desc 'Validate CloudFormation template files'
task :test do
Dir.glob('*.json').each do |template|
puts "Validating template #{template}"
result = validate_template(File.read(template))
if result.has_key?(:code)
abort "#{result[:code]}: #{result[:message]}"
end
# Do not exceed API rate limit
sleep(0.5)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment