-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredalert.yml
182 lines (182 loc) · 4.63 KB
/
redalert.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Redalert Stack
Parameters:
VPCParameter:
Description: VPC to launch instances into
Type: AWS::EC2::VPC::Id
SubnetsParameter:
Description: Subnets to launch instances into
Type: List<AWS::EC2::Subnet::Id>
RedalertConfigURL:
Description: URL for Redalert Config
Type: String
Default: https://myserver.com/config.json
RedalertVersion:
Description: Redalert Version
Type: String
Default: "0.2.3"
ConfigureDns:
Description: Toggle configuring DNS
Type: String
Default: 'false'
AllowedValues:
- 'true'
- 'false'
R53HostedZoneName:
Description: "(Optional Configure DNS) Hosted DNS Name."
Type: String
Default: randomdomain.com
Mappings:
RegionMap:
eu-west-1:
AMI: ami-bff32ccc
ap-southeast-1:
AMI: ami-c9b572aa
ap-southeast-2:
AMI: ami-48d38c2b
eu-central-1:
AMI: ami-bc5b48d0
ap-northeast-2:
AMI: ami-249b554a
ap-northeast-1:
AMI: ami-383c1956
us-east-1:
AMI: ami-60b6c60a
sa-east-1:
AMI: ami-6817af04
us-west-1:
AMI: ami-d5ea86b5
us-west-2:
AMI: ami-f0091d91
Conditions:
ConfigureRoute53:
Fn::Equals:
- Ref: ConfigureDns
- 'true'
Resources:
ELBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: elb-sg
SecurityGroupEgress:
- IpProtocol: "-1"
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80
VpcId:
Ref: VPCParameter
ELB:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
ConnectionDrainingPolicy:
Enabled: true
Timeout: 30
CrossZone: true
HealthCheck:
HealthyThreshold: '2'
Interval: '10'
Target: HTTP:80/
Timeout: '5'
UnhealthyThreshold: '2'
Listeners:
- InstancePort: '80'
InstanceProtocol: HTTP
LoadBalancerPort: '80'
Protocol: HTTP
Scheme: internet-facing
SecurityGroups:
- !Ref ELBSecurityGroup
Subnets: !Ref SubnetsParameter
EC2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: ec2-sg
SecurityGroupEgress:
- IpProtocol: "-1"
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 22
IpProtocol: tcp
ToPort: 22
- FromPort: 80
IpProtocol: tcp
SourceSecurityGroupId: !Ref ELBSecurityGroup
ToPort: 80
VpcId: !Ref VPCParameter
ElbDnsCname:
Condition: ConfigureRoute53
Type: AWS::Route53::RecordSet
DependsOn: ELB
Properties:
HostedZoneName:
Fn::Join:
- ''
- - Ref: R53HostedZoneName
- "."
Comment: CNAME Redirect to the ELB
Name:
Fn::Join:
- ''
- - Ref: AWS::StackName
- "."
- Ref: R53HostedZoneName
- "."
Type: CNAME
TTL: '300'
ResourceRecords:
- Fn::GetAtt:
- ELB
- DNSName
LaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
AssociatePublicIpAddress: true
ImageId: !FindInMap [RegionMap, !Ref 'AWS::Region', AMI]
InstanceType: t2.micro
SecurityGroups:
- !Ref EC2SecurityGroup
UserData:
'Fn::Base64': !Sub |
#!/bin/bash -ex
yum -y install wget
wget https://github.com/jonog/redalert/releases/download/v${RedalertVersion}/redalert_${RedalertVersion}_linux_amd64.tar.gz
tar -xvf redalert_${RedalertVersion}_linux_amd64.tar.gz
nohup ./redalert -p 80 --config-url=${RedalertConfigURL} server &
/opt/aws/bin/cfn-signal -e 0 --region ${AWS::Region} --stack ${AWS::StackName} --resource AutoScalingGroup
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MinSize: '1'
MaxSize: '2'
DesiredCapacity: '1'
LaunchConfigurationName: !Ref LaunchConfiguration
VPCZoneIdentifier: !Ref SubnetsParameter
LoadBalancerNames:
- !Ref ELB
HealthCheckGracePeriod: 60
HealthCheckType: ELB
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: PT10M
UpdatePolicy:
AutoScalingRollingUpdate:
MaxBatchSize: '2'
MinInstancesInService: '1'
PauseTime: PT10M
SuspendProcesses:
- AlarmNotification
WaitOnResourceSignals: true
Outputs:
RedalertWebURL:
Value:
Fn::Join:
- ''
- - 'http://'
- !Ref ElbDnsCname
Description: Redalert Web URL