Skip to content

Instantly share code, notes, and snippets.

@mipearson
Created February 28, 2011 05:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mipearson/846969 to your computer and use it in GitHub Desktop.
Save mipearson/846969 to your computer and use it in GitHub Desktop.
Mockup for a DSL to generate Amazon CloudFormation configurations
# Based on half of https://s3.amazonaws.com/cloudformation-templates-us-east-1/WordPress-1.0.0.template
# Methods beginning with a lowercase letter are 'native' and have special behaviour.
# Methods beginning with an uppercase letter get literally transformed into JSON
templates do
Alarm do
EvaluationPeriods 1
Statistic 'Average'
Period 60
AlarmActions: ref('AlarmTopic')
Namespace "AWS/EC2"
InsufficientDataActions ref('AlarmTopic')
end
end
cloud_formation do
Description "WordPress is web software you can use to create a beautiful website or blog. This template creates a scalable WordPress installation using an Auto Scaling group behind an Elastic Load Balancer along with an Amazon Relational Database Service database instance to store the content."
parameters do
KeyName "Name of an existing EC2 KeyPair to enable SSH access into the WordPress web server"
WordPressDBName "The WordPress database name", 'wordpress'
WordPressUser "The WordPress database admin account user", "admin", :noecho => true
WordPressPwd "The WordPress database admin account password", "admin", :noecho => true
GroupSize "The initial number of EC2 instances for the WordPress web server", '1'
InstanceType "The type of EC2 instances used for the WordPress web server", 'm1.small'
OperatorEmail "Email address to notify if there are any operational issues", "nobody@amazon.com"
WordPressDBPort "TCP/IP port for the WordPress database", '8443'
WebServerPort "TCP/IP port for the WordPress web server", '8443'
end
resources do
CPUAlarmHigh 'AWS::CloudWatch::Alarm' do
merge Alarm
Threshhold 10
AlarmDescription "Alarm if CPU too high or metric disappears indicating instance is down"
Dimensions :name => 'AutoScalingGroupName', :value => ref('WebServerGroup')
ComparisonOperator "GreaterThanThreshold"
MetricName "CPUUtilization"
end
TooManyUnhealthyHostsAlarm 'AWS::CloudWatch::Alarm' do
merge Alarm
Threshold "0"
Dimensions :name => "LoadBalancerName", :value => ref('ElasticLoadBalancer')
ComparisonOperator "GreaterThanThreshold"
MetricName "UnHealthyHostCount"
end
EC2SecurityGroup 'AWS::EC2::SecurityGroup' do
SecurityGroupIngress [
{:FromPort => 22, :CidrIp => '0.0.0.0/0', :ToPort => 22, :IpProtocol => 'tcp'},
{:FromPort => ref('WebServerPort'), :CidrIp => '0.0.0.0/0', :ToPort => ref('WebServerPort'), :IpProtocol => 'tcp'},
]
GroupDescription "HTTP and SSH access"
end
RequestLatencyAlarmHigh 'AWS::CloudWatch::Alarm' do
merge Alarm
Threshold 1
AlarmDescription "Alarm if there aren't any requests coming through."
Dimensions :name => "LoadBalancerName", :value => ref('ElasticLoadBalancer')
ComparisonOperator "GreaterThanThreshold"
MetricName "Latency"
end
ElasticLoadBalancer 'AWS::ElasticLoadBalancing::LoadBalancer' do
Listeners [
lambda do
InstancePort ref('WebServerPort')
PolicyNames ['p1']
Protocol 'HTTP'
LoadBalancerPort '80'
end
]
HealthCheck do
HealthyThreshold 2
Timeout 5
Interval 10
UnhealthyThreshold 5
Target ['HTTP://', ref('WebServerPort'), '/wp-admin/install.php'].fn_join('')
end
AvailabilityZones fn_GetAZs(ref('AWS::Region'))
LBCookieSticknessPolicy [
lambda do
CookieExpirationPeriod 30
PolicyName 'p1'
end
]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment