A Ruby gem to create AWS CloudFormation descriptions.
Add this line to your application's Gemfile:
gem 'cloud_formation'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cloud_formation
template = CloudFormation::Template.new
template.build do |t|
t.name = "stack-name"
t.description = "A description of the stack"
end
template.render
Running this will generate a nicely compacted:
{"AWSTemplateFormatVersion":"2010-09-09","Name":"stack-name","Description":"A description of the stack","Resources":{}}
Generating a DynamoDB table is as simple as:
template = CloudFormation::Template.new
template.build do |t|
t.name = "stack-name"
t.description = "A description of the stack"
end
dynamo_db = CloudFormation::DynamoDB.new
table = dynamo_db.build_table do |t|
t.name = "commentsTable"
t.read_capacity_units = 10
t.write_capacity_units = 5
t.hash_key = { blog_post_id: :number }
t.range_key = { comment_id: :number }
end
template.add_resource table
puts template.render pretty: true
Running with the pretty true
options will generate an easier to read version:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Name": "stack-name",
"Description": "A description of the stack",
"Resources": {
"commentsTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"ProvisionedThroughput": {
"WriteCapacityUnits": "5",
"ReadCapacityUnits": "10"
},
"KeySchema": {
"RangeKeyElement": {
"AttributeName": "comment_id",
"AttributeType": "N"
},
"HashKeyElement": {
"AttributeName": "blog_post_id",
"AttributeType": "N"
}
}
}
}
}
}
- Fork it ( http://github.com/davidrhyswhite/cloud_formation/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request