forked from fizx/pincer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf.yaml
178 lines (177 loc) · 5.09 KB
/
cf.yaml
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
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'ipfs pin server'
Parameters:
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
OperatorEMail:
Description: EMail address to notify if there are any scaling operations
Type: String
AllowedPattern: "([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)"
ConstraintDescription: must be a valid email address.
KeyName:
Description: The EC2 Key Pair to allow SSH access to the instances
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: must be the name of an existing EC2 KeyPair.
ApiKey:
Description: An API key for access to setting and removing pins
Type: String
SSHLocation:
Description: The IP address range that can be used to SSH to the EC2 instances
Type: String
MinLength: '9'
MaxLength: '18'
Default: 0.0.0.0/0
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
Resources:
S3Role:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "ec2.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
Policies:
-
PolicyName: {"Fn::Join": ["", ["s3", {"Ref": "AWS::Region"}, {"Ref": "Bucket"}]]}
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action: "*"
Resource: {"Fn::Join": ["", ["arn:aws:s3:::", {"Ref": "Bucket"}, "/*"]]}
-
Effect: "Allow"
Action: "*"
Resource: {"Fn::Join": ["", ["arn:aws:s3:::", {"Ref": "Bucket"}]]}
InstanceProfile:
Type: "AWS::IAM::InstanceProfile"
Properties:
Path: "/"
Roles:
-
Ref: "S3Role"
Bucket:
Type: AWS::S3::Bucket
NotificationTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint:
Ref: OperatorEMail
Protocol: email
WebServerGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones:
Fn::GetAZs: ''
LaunchConfigurationName:
Ref: LaunchConfig
MinSize: '1'
MaxSize: '1'
LoadBalancerNames:
- Ref: ElasticLoadBalancer
NotificationConfiguration:
TopicARN:
Ref: NotificationTopic
NotificationTypes:
- autoscaling:EC2_INSTANCE_LAUNCH
- autoscaling:EC2_INSTANCE_LAUNCH_ERROR
- autoscaling:EC2_INSTANCE_TERMINATE
- autoscaling:EC2_INSTANCE_TERMINATE_ERROR
LaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
KeyName:
Ref: KeyName
ImageId: ami-7ed1a006
SecurityGroups:
- Ref: InstanceSecurityGroup
IamInstanceProfile:
Ref: InstanceProfile
InstanceType:
Ref: InstanceType
UserData:
Fn::Base64:
Fn::Join:
- ""
- - "#!/bin/bash -xe\n"
- "wget https://ipfs.io/ipfs/QmcWZbsRZDuxyPLciSVt3Q1zqowpv2MJBMwYX5AZCh2t9j -O /tmp/startup\n"
- "chmod +x /tmp/startup\n"
- "sudo -u ubuntu /tmp/startup "
- {Ref: ApiKey}
- " "
- {Ref: Bucket}
ElasticLoadBalancer:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
AvailabilityZones:
Fn::GetAZs: ''
CrossZone: 'true'
Listeners:
- LoadBalancerPort: '443'
InstancePort: '443'
Protocol: TCP
SecurityGroups:
- Fn::GetAtt:
- ELBSecurityGroup
- GroupId
HealthCheck:
Target: TCP:443
HealthyThreshold: '3'
UnhealthyThreshold: '5'
Interval: '30'
Timeout: '5'
ELBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable HTTPS from everywhere
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access and HTTP from the load balancer only
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp:
Ref: SSHLocation
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
SourceSecurityGroupOwnerId:
Fn::GetAtt:
- ElasticLoadBalancer
- SourceSecurityGroup.OwnerAlias
SourceSecurityGroupName:
Fn::GetAtt:
- ElasticLoadBalancer
- SourceSecurityGroup.GroupName
Outputs:
URL:
Description: The URL of the website
Value:
Fn::Join:
- ''
- - https://
- Fn::GetAtt:
- ElasticLoadBalancer
- DNSName