The enormous indexes are also largely autogenerated.
NOTE: I suggest you that you DO NOT use this library in a production environment. There are approximately
400 files, and they are ALL included as soon as you require('botox'). It probably won't
fry your server, but it's a little wasteful for a production environment that cares about performance.
This library is useful if you want to:
document parts of your CloudFormation templates (since JSON doesn't allow comments, among other things)
eliminate duplicated resources, e.g. a subnet in every availability zone can be accomplished using a loop
instead of copying the same subnet resource multiple times
write code instead of markup
not type double quotes, or Fn::Join with its copious array arguments
Installation
npm install botox
Usage
In the grand spirit of JavaScript libraries, Botox uses a fluent interface so you don't have
to do annoying stuff like type new.
If your editor is cool enough, you will get super excellentish intellisense as you type stuff,
which is extraordinarily helpful since unless you're psychotic you're not going to remember the
options for every single resource. It's also very helpful for discovery of resources/options
you might not be aware of.
The easiest way to figure stuff out is to use a cool enough editor and just start typing.
Hopefully your editor is rad and you'll see something that looks like this:
Example
//a portion of the sample template at https://s3.amazonaws.com/cloudformation-templates-us-east-1/WordPress_Multi_AZ.template
constbotox=require('botox');
botox.parameter('KeyName')
.description('Name of an existing EC2 KeyPair to enable SSH access to the instances')
.type('AWS::EC2::KeyPair::KeyName')
.constraintDescription('must be the name of an existing EC2 KeyPair.');
"Description":"Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type":"AWS::EC2::KeyPair::KeyName",
"ConstraintDescription":"must be the name of an existing EC2 KeyPair."
}
},
"Conditions":{
"Is-EC2-VPC":{
"Fn::Or":[
{
"Fn::Equals":[
{
"Ref":"AWS::Region"
},
"eu-central-1"
]
},
{
"Fn::Equals":[
{
"Ref":"AWS::Region"
},
"cn-north-1"
]
},
{
"Fn::Equals":[
{
"Ref":"AWS::Region"
},
"ap-northeast-2"
]
}
]
},
"Is-EC2-Classic":{
"Fn::Not":[
{
"Condition":"Is-EC2-VPC"
}
]
}
},
"Resources":{
"ElasticLoadBalancer":{
"Type":"AWS::ElasticLoadBalancing::LoadBalancer",
"Properties":{
"CrossZone":true,
"AvailabilityZones":{
"Fn::GetAZs":""
},
"LBCookieStickinessPolicy":[
{
"PolicyName":"CookieBasedPolicy",
"CookieExpirationPeriod":"30"
}
],
"Listeners":[
{
"LoadBalancerPort":"80",
"InstancePort":"80",
"Protocol":"HTTP",
"PolicyNames":[
"CookieBasedPolicy"
]
}
],
"HealthCheck":{
"Target":"HTTP:80/",
"HealthyThreshold":"2",
"UnhealthyThreshold":"5",
"Interval":"10",
"Timeout":"5"
}
}
}
}
}
Refs
You can also easily get references to resources by using the .ref property, e.g.
lb.ref would equivalent to { "Ref": "ElasticLoadBalancer" } in the example above.
Attributes
The equivalent of Fn::GetAtt is a property on each resource instance: