"The cnfdsl gem provides a simple DSL that allows you to write equivalent templates in a more friendly language and generate the correct json templates from the CLI"
CloudFormation {
Description "Test"
Parameter("One") {
String
Default "Test"
MaxLength 15
}
Output(:One,FnBase64( Ref("One")))
Resource("MyInstance") {
Type "AWS::EC2::Instance"
Property("ImageId","ami-14341342")
}
}
bash-3.2$ cfndsl /path/to/my/template.rb
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Test",
"Outputs": {
"One": {
"Value": {
"Fn::Base64": {
"Ref": "One"
}
}
}
},
"Parameters": {
"One": {
"Default": "Test",
"MaxLength": 15,
"Type": "String"
}
},
"Resources": {
"MyInstance": {
"Properties": {
"ImageId": "ami-14341342"
},
"Type": "AWS::EC2::Instance"
}
}
}
Parameter "SQSRetentionPeriod" do
String
Description "The Retention period for the queues generated in this example"
end
queues = [
'TestOne',
'TestTwo'
]
queues.each do |name|
Resource "#{name}Queue" do
Type "AWS::SQS::Queue"
Property "MessageRetentionPeriod", Ref("SQSRetentionPeriod")
end
end
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"SQSRetentionPeriod": {
"Default": 300,
"Description": "The Retention period for the queues generated in this example",
"Type": "String"
}
},
"Resources": {
"TestOneQueue": {
"Properties": {
"MessageRetentionPeriod": {
"Ref": "SQSRetentionPeriod"
}
},
"Type": "AWS::SQS::Queue"
},
"TestTwoQueue": {
"Properties": {
"MessageRetentionPeriod": {
"Ref": "SQSRetentionPeriod"
}
},
"Type": "AWS::SQS::Queue"
}
}
}
end
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"SQSRetentionPeriod": {
"Default": 300,
"Description": "The Retention period for the queues generated in this example",
"Type": "String"
}
},
"Resources": {
"TestOneQueue": {
"Properties": {
"MessageRetentionPeriod": {
"Ref": "SQSRetentionPeriod"
}
},
"Type": "AWS::SQS::Queue"
},
"TestTwoQueue": {
"Properties": {
"MessageRetentionPeriod": {
"Ref": "SQSRetentionPeriod"
}
},
"Type": "AWS::SQS::Queue"
}
}
}
end
The samples folder in the cfndsl repo has an example that builds the standard cloudformation autoscaling template:
gem install bbc-cosmos-tools bash-3.2$ bbc-cosmos-tools stack update election-data-renderer --env=test