Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ozbillwang/bbfdbb9ca858786ad6c1 to your computer and use it in GitHub Desktop.
Save ozbillwang/bbfdbb9ca858786ad6c1 to your computer and use it in GitHub Desktop.
How to run use "bazaarvoice/cloudformation-ruby-dsl" to generate cloudformation template

I was recommended to use github repository bazaarvoice/cloudformation-ruby-dsl to generate cloudformation template. But its README is not good enough.

Here are the steps on how to use it on my mac with bundler

$ git clonehttps://github.com/bazaarvoice/cloudformation-ruby-dsl.git
$ cd cloudformation-ruby-dsl
$ bundle install
$ bundle exec rake -T
rake build          # Build cloudformation-ruby-dsl-1.0.4.gem into the pkg directory
rake install        # Build and install cloudformation-ruby-dsl-1.0.4.gem into system gems
rake install:local  # Build and install cloudformation-ruby-dsl-1.0.4.gem into system g...
rake release        # Create tag v1.0.4 and build and push cloudformation-ruby-dsl-1.0....

$ bundle exec rake build
cloudformation-ruby-dsl 1.0.4 built to pkg/cloudformation-ruby-dsl-1.0.4.gem.

$ bundle exec cfntemplate-to-ruby --help
usage: /Users/bill/.rvm/gems/ruby-2.0.0-p643/bin/cfntemplate-to-ruby [cloudformation-template.json] ...

Converts the specified CloudFormation JSON template or template fragment to
Ruby DSL syntax.  Reads from stdin or from the specified json files.  Note
that the input must be valid JSON.

Examples:

    # Convert a JSON CloudFormation template to Ruby DSL syntax
    /Users/bill/.rvm/gems/ruby-2.0.0-p643/bin/cfntemplate-to-ruby my-template.json > my-template.rb
    chmod +x my-template.rb

    # Convert the JSON fragment in the clipboard to Ruby DSL syntax
    pbpaste | /Users/bill/.rvm/gems/ruby-2.0.0-p643/bin/cfntemplate-to-ruby | less

# download the sample template at: https://s3-us-west-2.amazonaws.com/cloudformation-templates-us-west-2/EC2InstanceWithSecurityGroupSample.template
$ bundle exec cfntemplate-to-ruby EC2InstanceWithSecurityGroupSample.template > sample.rb

$ bundle exec ruby sample.rb
usage: sample.rb <expand|diff|validate|create|update|cancel-update|delete|describe|describe-resource|get-template>

$ bundle exec ruby sample.rb expand > sample.templte
$ bundle exec ruby sample.rb validate sample.templte
Validation successful
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment