-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws-pools.yaml
171 lines (150 loc) · 4.64 KB
/
aws-pools.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
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template for creating an EC2 instance with S3 access.
Parameters:
UbuntuAmiId:
Type: String
Description: The AMI ID for the Ubuntu instance
SeedParameter:
Type: String
Description: Seed parameter for the pool creation script
Resources:
FulaInternetGateway:
Type: AWS::EC2::InternetGateway
FulaVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
FulaRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref FulaVPC
FulaVPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref FulaVPC
InternetGatewayId: !Ref FulaInternetGateway
FulaRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref FulaRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref FulaInternetGateway
FulaSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref FulaSubnet
RouteTableId: !Ref FulaRouteTable
FulaSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref FulaVPC
CidrBlock: 10.0.0.0/24
FulaSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupName: fula-node
GroupDescription: Security Group for Fula Node
VpcId: !Ref FulaVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
FulaVolume:
Type: AWS::EC2::Volume
Properties:
Size: 30
AvailabilityZone: !GetAtt FulaEC2Instance.AvailabilityZone
VolumeType: gp2
FulaVolumeAttachment:
Type: AWS::EC2::VolumeAttachment
Properties:
InstanceId: !Ref FulaEC2Instance
VolumeId: !Ref FulaVolume
Device: /dev/sdh
FulaInstanceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: FulaInstancePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
Resource: 'arn:aws:s3:::fula-pools/*'
FulaInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref FulaInstanceRole
FulaEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: m5.8xlarge
IamInstanceProfile: !Ref FulaInstanceProfile
ImageId: !Ref UbuntuAmiId
KeyName: functionland
Tags:
- Key: Name
Value: fula-pool
- Key: Group
Value: pools
NetworkInterfaces:
- DeviceIndex: '0'
AssociatePublicIpAddress: true
SubnetId: !Ref FulaSubnet
GroupSet:
- !Ref FulaSecurityGroup
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: 30
DeleteOnTermination: true
VolumeType: gp2
UserData:
Fn::Base64: !Sub |
#!/bin/bash
# Wait for the attached volume to become available
while ! sudo lsblk | grep -q nvme1n1; do
sleep 1
done
echo "EBS volume is attached"
# Create a filesystem on the volume (if it's new)
sudo mkfs -t ext4 /dev/nvme1n1
# Create the mount point directory
sudo mkdir -p /uniondrive
# Mount the volume
sudo mount /dev/nvme1n1 /uniondrive
sudo chown ubuntu:ubuntu /uniondrive
sudo chmod 777 -R /uniondrive
# Add an entry to /etc/fstab to auto-mount the volume on reboot
echo "/dev/nvme1n1 /uniondrive ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
# Update and install NTP
sudo apt-get update
sudo apt-get install -y ntp
# Once NTP is installed, query the NTP servers
sudo ntpq -p
# Clone the repository
git clone https://github.com/functionland/automatic-poolnode-creation-script /home/ubuntu/automatic-poolnode-creation-script
# Run the script with the provided seed parameter
# sudo -u ubuntu bash /home/ubuntu/automatic-poolnode-creation-script/pool_creation.sh ${SeedParameter}