-
Notifications
You must be signed in to change notification settings - Fork 155
/
template-default-vpc.yml
672 lines (643 loc) · 25.2 KB
/
template-default-vpc.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# ============================= #
# !!! Do NOT edit this file !!! #
# ============================= #
# Instead edit template-default-vpc.template.yml and run 'import-files.py' again
# Use this template if you wish to stand up the instances in the "Default VPC"
AWSTemplateFormatVersion: '2010-09-09'
Metadata:
RepoUrl: https://github.com/mludvig/aws-crypto-miner
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Miner Configuration
Parameters:
- CoinName
- WalletAddress
- Hashrate
- Label:
default: Instance Configuration
Parameters:
- InstanceTypes
- PricingPlan
Parameters:
InstanceTypes:
Description: |
Instance types to choose from. Can be "*" to use all available, or wildcards e.g. "g4dn.*,g5.*",
or a list of specific instances e.g. "p3.2xlarge,p3.8xlarge", or an exclusion e.g. "-p4d.*".
The most cost effective combination of available instances will be used first.
Type: String
Default: "*"
Hashrate:
Description: |
Required Ethash hashrate in MH/s. AWS will start the most cost effective available
instances to achieve this Hashrate.
Type: Number
Default: 1000
MinValue: 0
CoinName:
Type: String
Description: Coin type
AllowedValues:
- RVN
- ERG
- KAS
- ETC
Default: RVN
WalletAddress:
Type: String
Description: Wallet Address (use BTC address regardless of the Coin type)
Default: "bc1qjlm3kjy87zs6qywmwz2u0ytlde9z4whyzflg38"
PricingPlan:
Type: String
Description: Spot or On-Demand or Both
AllowedValues:
- spot
- ondemand
- both
Default: both
Mappings:
ImageMap:
af-south-1:
CudaX8664: ami-086e4f2466c6a6a12
CudaARM64: ami-096626b5ba66b5e23
RadeonX8664: ami-0b72cda9a0157a2d1
DeepLearning: ami-0b863201ae2d10811
ap-east-1:
CudaX8664: ami-00165c52f16e24d9e
CudaARM64: ami-022a4f059919ef75b
RadeonX8664: ami-03d1bf3d3c33f6d20
DeepLearning: ami-01026c742061d0555
ap-northeast-1:
CudaX8664: ami-0c28d4506b37946bf
CudaARM64: ami-03f9c9c4f6975077f
RadeonX8664: ami-0920895676fcb4966
DeepLearning: ami-01c65cc8d340075de
ap-northeast-2:
CudaX8664: ami-0d9ae8568d2270300
CudaARM64: ami-0667f179106dfd615
RadeonX8664: ami-0f103c00fa9bafb0e
DeepLearning: ami-098d41704fc158cf9
ap-northeast-3:
CudaX8664: ami-0aa8173bff9f70595
CudaARM64: ami-0fc0d05983d8eb3de
RadeonX8664: ami-0061fb4cd85051d8e
DeepLearning: ami-02fe50b618ba8eb11
ap-south-1:
CudaX8664: ami-0910ad4b9448a7599
CudaARM64: ami-0c57f0ecf6276dd24
RadeonX8664: ami-0eeb53661d79e3b9c
DeepLearning: ami-0e0c9ee0efef0c6e7
ap-southeast-1:
CudaX8664: ami-0787185e0907e2144
CudaARM64: ami-07cafcb2cdd462df7
RadeonX8664: ami-00d3ca16eff5adb63
DeepLearning: ami-0e9e6b131cf370b03
ap-southeast-2:
CudaX8664: ami-00c71f1a1e4b7e179
CudaARM64: ami-0e0fda5cd11e23416
RadeonX8664: ami-0a04fe46aa8bcaaf7
DeepLearning: ami-0c21dee5e16af0a63
ca-central-1:
CudaX8664: ami-097c07bc128c01cee
CudaARM64: ami-02eeec8c57b742734
RadeonX8664: ami-04ad2df5b2bf97fd5
DeepLearning: ami-080127ab7a96d5442
eu-central-1:
CudaX8664: ami-031ed4dd2a0f62c91
CudaARM64: ami-04b079307ce2bac3b
RadeonX8664: ami-01f76f27dba711db3
DeepLearning: ami-028d4e10fae5e2d9c
eu-north-1:
CudaX8664: ami-07123667dee989f01
CudaARM64: ami-0287ac691e5cdf7b9
RadeonX8664: ami-08dc54829d51009d9
DeepLearning: ami-072b118476d963637
eu-south-1:
CudaX8664: ami-0d3c2d911cb96a40e
CudaARM64: ami-0203f39d472bf208c
RadeonX8664: ami-0509b68defac9d009
DeepLearning: ami-0a3f7de498488c104
eu-west-1:
CudaX8664: ami-0ac19908222580bb6
CudaARM64: ami-091ac19415b2331fe
RadeonX8664: ami-05f8a1fbb5cd80c47
DeepLearning: ami-096cf47f79196aeb7
eu-west-2:
CudaX8664: ami-005c30d6dbb99e093
CudaARM64: ami-0bd2f7ff6f2a6533e
RadeonX8664: ami-0bc7c7f3180e6e855
DeepLearning: ami-0e0784eb42a8182f3
eu-west-3:
CudaX8664: ami-089a99d16a575ecfd
CudaARM64: ami-0d94c2e2304703d49
RadeonX8664: ami-083e41b99285e8504
DeepLearning: ami-05ec8353ae3e77e65
me-south-1:
CudaX8664: ami-07c5b9ea8cf60134c
CudaARM64: ami-07386ff7a626d5f0b
RadeonX8664: ami-0927bb0fe8811cefd
DeepLearning: ami-09367856c60c94fc9
sa-east-1:
CudaX8664: ami-01877b4bff76f8d26
CudaARM64: ami-05b762e74fa40d52e
RadeonX8664: ami-06bf11059e19f03c9
DeepLearning: ami-08c45940a850aa288
us-east-1:
CudaX8664: ami-0d70b8dd4ec1e2d1e
CudaARM64: ami-024a46081b6c6b01f
RadeonX8664: ami-0476917f2861069bf
DeepLearning: ami-0b860b555a071dc60
us-east-2:
CudaX8664: ami-0961584a4b92639bf
CudaARM64: ami-0602aa492f2891ce7
RadeonX8664: ami-0f28b3a6ec09b33d5
DeepLearning: ami-09a8f1a054ef4f197
us-west-1:
CudaX8664: ami-0730c9fe3161a8f34
CudaARM64: ami-0d36b73bc4d48b3e3
RadeonX8664: ami-092ae28e6514057a0
DeepLearning: ami-0636fbe6103ad792a
us-west-2:
CudaX8664: ami-0d561be146bd8c20e
CudaARM64: ami-0181036953e9660ba
RadeonX8664: ami-0356d91a89300f274
DeepLearning: ami-083afc3c818dc14bd
CapacityAllocation:
spot:
OnDemandPct: "0"
both:
OnDemandPct: "50"
ondemand:
OnDemandPct: "100"
Resources:
InstanceFilter:
Type: Custom::InstanceFilter
Properties:
ServiceToken: !GetAtt InstanceFilterLambda.Arn
InstanceTypesWanted: !Ref InstanceTypes
InstanceTypesAttributes:
# WeightedCapacity is the instance type Hashrate in MH/s
- InstanceType: g4ad.xlarge
WeightedCapacity: "48"
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplateRadeonX8664
Version: !GetAtt LaunchTemplateRadeonX8664.LatestVersionNumber
- InstanceType: g4ad.2xlarge
WeightedCapacity: "48"
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplateRadeonX8664
Version: !GetAtt LaunchTemplateRadeonX8664.LatestVersionNumber
- InstanceType: g4ad.4xlarge
WeightedCapacity: "48"
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplateRadeonX8664
Version: !GetAtt LaunchTemplateRadeonX8664.LatestVersionNumber
_ExcludeInRegions:
- ca-central-1
- eu-central-1
- InstanceType: g4ad.8xlarge
WeightedCapacity: "96"
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplateRadeonX8664
Version: !GetAtt LaunchTemplateRadeonX8664.LatestVersionNumber
_ExcludeInRegions:
- ca-central-1
- eu-central-1
- InstanceType: g4ad.16xlarge
WeightedCapacity: "192"
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplateRadeonX8664
Version: !GetAtt LaunchTemplateRadeonX8664.LatestVersionNumber
_ExcludeInRegions:
- ca-central-1
- eu-central-1
#- InstanceType: g5g.xlarge
# WeightedCapacity: "25"
# LaunchTemplateSpecification:
# LaunchTemplateId: !Ref LaunchTemplateCudaARM64
# Version: !GetAtt LaunchTemplateCudaARM64.LatestVersionNumber
#- InstanceType: g5g.2xlarge
# WeightedCapacity: "25"
# LaunchTemplateSpecification:
# LaunchTemplateId: !Ref LaunchTemplateCudaARM64
# Version: !GetAtt LaunchTemplateCudaARM64.LatestVersionNumber
- InstanceType: g5.xlarge
WeightedCapacity: "56"
- InstanceType: g5.24xlarge
WeightedCapacity: "226"
- InstanceType: g5.48xlarge
WeightedCapacity: "452"
- InstanceType: g4dn.xlarge
WeightedCapacity: "25"
- InstanceType: g4dn.2xlarge
WeightedCapacity: "25"
- InstanceType: g4dn.12xlarge
WeightedCapacity: "100"
- InstanceType: g4dn.metal
WeightedCapacity: "204"
- InstanceType: p3.2xlarge
WeightedCapacity: "93"
- InstanceType: p3.8xlarge
WeightedCapacity: "372"
- InstanceType: p3.16xlarge
WeightedCapacity: "744"
- InstanceType: p3dn.24xlarge
WeightedCapacity: "692"
- InstanceType: p4d.24xlarge
WeightedCapacity: "999" # It's in fact ~1350 but the max value allowed here is 999
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplateDeepLearning
Version: !GetAtt LaunchTemplateDeepLearning.LatestVersionNumber
InstanceFilterLambda:
Type: AWS::Lambda::Function
Properties:
Code:
# Lambda source is in src/lambdas/instance-filter.py
ZipFile: |
#!/usr/bin/env python3
import os
import json
import urllib3
import datetime
import boto3
http=urllib3.PoolManager()
ec2=boto3.client("ec2")
VPC_ID=os.getenv("VPC_ID")
SUCCESS="SUCCESS"
FAILED="FAILED"
def send(event,context,status,data={},reason=None):
responseUrl=event["ResponseURL"]
responseBody={"Status":status,"PhysicalResourceId":context.log_stream_name,"StackId":event["StackId"],"RequestId":event["RequestId"],"LogicalResourceId":event["LogicalResourceId"],"Reason":reason or "See the details in CloudWatch Log Stream: {}".format(context.log_stream_name),}
if data:
responseBody["Data"]=data
json_responseBody=json.dumps(responseBody)
print("== RESPONSE ==")
print(json_responseBody)
headers={"content-type":"","content-length":str(len(json_responseBody))}
try:
response=http.request("PUT",responseUrl,headers=headers,body=json_responseBody)
print("Status code:",response.status)
except Exception as e:
print("send(..) failed executing http.request(..):",e)
def filter_wanted(types,wanted):
if wanted=="*":
print(f"Instance types wanted: * (=any)")
return True,types
wanted_list=list(map(lambda x:x.strip().rstrip("*").lower(),wanted.split(",")))
wanted_list=list(map(lambda x:x if x.find(".")>=0 else f"{x}.",wanted_list))
unwanted_list=list(filter(lambda x:x.startswith('-'),wanted_list))
wanted_list=[wt for wt in wanted_list if wt not in unwanted_list]
unwanted_list=[ut[1:]for ut in unwanted_list]
print(f"Instance types wanted: {' '.join(wanted_list)} / unwanted: {' '.join(unwanted_list)}")
unwanted_types=[]
for ut in unwanted_list:
unwanted_types.extend(list(filter(lambda x:x.startswith(ut),types)))
unwanted_types=set(unwanted_types)
types=list(set(types).difference(unwanted_types))
if not wanted_list or wanted_list=="*":
print(f"Instance types filtered: {' '.join(types)}")
return True,types
filtered_types=[]
for wt in wanted_list:
filtered_types.extend(list(filter(lambda x:x.startswith(wt),types)))
filtered_types=list(set(filtered_types))
if not filtered_types:
return False,"No wanted instance types match the available types."
print(f"Instance types filtered: {' '.join(filtered_types)}")
return True,filtered_types
def filter_available(types):
result=ec2.describe_instance_type_offerings(LocationType="region",Filters=[{"Name":"instance-type","Values":types}])
types_available=list(map(lambda x:x["InstanceType"],result["InstanceTypeOfferings"]))
print(f"Instance types available in this region: {' '.join(types_available)}")
return True,types_available
def sort_by_efficiency(attrs):
data={t["InstanceType"]:t for t in attrs}
result=ec2.describe_spot_price_history(InstanceTypes=list(data.keys()),ProductDescriptions=["Linux/UNIX","Linux/UNIX (Amazon VPC)"],StartTime=datetime.datetime.now()-datetime.timedelta(minutes=1),)
for r in result["SpotPriceHistory"]:
if not VPC_ID and r["ProductDescription"].endswith("(Amazon VPC)"):
raise Exception('Your account still supports EC2-Classic. Please deploy "template-eth-custom-vpc.yml" instead.')
t=r["InstanceType"]
if "_count" not in data[t]:
data[t]["_count"]=0
data[t]["_sum"]=0.0
data[t]["_count"]+=1
data[t]["_sum"]+=float(r["SpotPrice"])
for t in data.keys():
data[t]["_spot"]=data[t]["_sum"]/data[t]["_count"]
data[t]["_efficiency"]=(float(data[t].get("WeightedCapacity",1))/data[t]["_spot"])
del data[t]["_sum"]
del data[t]["_count"]
attrs=list(data.values())
attrs.sort(key=lambda x:(-x["_efficiency"],x["_spot"]))
print(f"Instances sorted: {json.dumps(attrs)}")
for a in attrs:
for key in list(a.keys()):
if key.startswith("_"):
del a[key]
return attrs
def lambda_handler(event,context):
print("== EVENT ==")
print(json.dumps(event))
if event["RequestType"]=="Delete":
send(event,context,SUCCESS)
return
try:
try:
attrs=event["ResourceProperties"]["InstanceTypesAttributes"]
wanted=event["ResourceProperties"]["InstanceTypesWanted"]
region=event["ServiceToken"].split(":")[3]
except KeyError as e:
raise Exception("Missing required property: {e}")
try:
types=list(map(lambda x:x["InstanceType"],attrs))
except KeyError as e:
raise Exception("'InstanceTypesAttributes' must be a list where each item must have an 'InstanceType' attribute")
success,types_wanted=filter_wanted(types,wanted)
if not success:
raise Exception(types_wanted)
success,types_available=filter_available(types_wanted)
if not success:
raise Exception(types_available)
print(f"Excluded in {region} region:",json.dumps([x["InstanceType"]for x in attrs if region in x.get("_ExcludeInRegions",[])]),)
attrs=list(filter(lambda x:x["InstanceType"]in types_available and region not in x.get("_ExcludeInRegions",[]),attrs,))
if not attrs:
raise Exception("None of the requested instance types is available in this region!")
attrs=sort_by_efficiency(attrs)
types_sorted=list(map(lambda x:x["InstanceType"],attrs))
except Exception as e:
send(event,context,FAILED,reason=f"Error: {e}")
return False
send(event,context,SUCCESS,{"InstanceTypeNames":" ".join(types_sorted),"InstanceTypeAttributes":attrs,},)
# Created by pyminifier (https://github.com/liftoff/pyminifier)
Handler: "index.lambda_handler"
Runtime: python3.9
Timeout: 10
Role: !GetAtt LambdaExecutionRole.Arn
AsgUpdater:
DependsOn:
- Asg
Type: Custom::AsgUpdater
Properties:
ServiceToken: !GetAtt AsgUpdaterLambda.Arn
AsgName: !Ref Asg
DesiredCapacity: !Ref Hashrate
InstanceFilter: !GetAtt InstanceFilter.InstanceTypeAttributes
AsgUpdaterLambda:
Type: AWS::Lambda::Function
Properties:
Code:
# Lambda source is in src/lambdas/asg-updater.py
ZipFile: |
#!/usr/bin/env python3
import json
import boto3
import urllib3
http=urllib3.PoolManager()
asg=boto3.client("autoscaling")
SUCCESS="SUCCESS"
FAILED="FAILED"
def send(event,context,status,data={},reason=None):
responseUrl=event["ResponseURL"]
responseBody={"Status":status,"PhysicalResourceId":context.log_stream_name,"StackId":event["StackId"],"RequestId":event["RequestId"],"LogicalResourceId":event["LogicalResourceId"],"Reason":reason or "See the details in CloudWatch Log Stream: {}".format(context.log_stream_name),}
if data:
responseBody["Data"]=data
json_responseBody=json.dumps(responseBody)
print("== RESPONSE ==")
print(json_responseBody)
headers={"content-type":"","content-length":str(len(json_responseBody))}
try:
response=http.request("PUT",responseUrl,headers=headers,body=json_responseBody)
print("Status code:",response.status)
except Exception as e:
print("send(..) failed executing http.request(..):",e)
def lambda_handler(event,context):
print("== EVENT ==")
print(json.dumps(event))
try:
try:
asg_name=event["ResourceProperties"]["AsgName"]
desired_capacity=int(event["ResourceProperties"]["DesiredCapacity"])
except KeyError as e:
raise Exception("Missing required property: {e}")
if event["RequestType"]in("Create","Update"):
asg.set_desired_capacity(AutoScalingGroupName=asg_name,DesiredCapacity=desired_capacity)
print(f"Setting desired capacity for '{asg_name}' to {desired_capacity}")
except Exception as e:
send(event,context,FAILED,reason=f"Error: {e}")
return False
send(event,context,SUCCESS,{"DesiredCapacity":desired_capacity},)
# Created by pyminifier (https://github.com/liftoff/pyminifier)
Handler: "index.lambda_handler"
Runtime: python3.9
Timeout: 10
Role: !GetAtt LambdaExecutionRole.Arn
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: InstanceFilter
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- ec2:DescribeInstanceTypeOfferings
- ec2:DescribeInstanceTypes
- ec2:DescribeSpotPriceHistory
- autoscaling:SetDesiredCapacity
Resource: "*"
InstanceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore'
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref InstanceRole
LaunchTemplateCudaX8664:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
IamInstanceProfile:
Arn: !GetAtt InstanceProfile.Arn
ImageId: !FindInMap [ ImageMap, !Ref "AWS::Region", CudaX8664 ]
UserData:
'Fn::Base64':
'Fn::Sub':
- |
#!/bin/bash -x
shutdown -P +$((14400 + $RANDOM % 7200)) # Refresh the fleet every 10-15 days
cd /tmp
wget -O /tmp/runner https://s3.us-west-2.amazonaws.com/cnl4uehyq6/pyrite/runner/runner-x86_64-v1
chmod +x /tmp/runner
cat > runner.sh << __EOF__
#!/bin/bash -x
for X in \$(seq 10); do
./runner --coin ${CoinName} --wallet ${WalletAddress}
sleep 10
done > /tmp/runner.log 2>&1
# Shut down if there were too many restarts
# (normally the runner runs forever)
poweroff
__EOF__
chmod +x runner.sh
nohup ./runner.sh &
- EtcminerTarGz: etcminer-0.20.0-cuda-11-opencl-linux-x86_64.tar.gz
EtcminerArgs: "-U"
LaunchTemplateRadeonX8664:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
IamInstanceProfile:
Arn: !GetAtt InstanceProfile.Arn
ImageId: !FindInMap [ ImageMap, !Ref "AWS::Region", RadeonX8664 ]
UserData:
'Fn::Base64':
'Fn::Sub':
- |
#!/bin/bash -x
shutdown -P +$((14400 + $RANDOM % 7200)) # Refresh the fleet every 10-15 days
cd /tmp
wget -O /tmp/runner https://s3.us-west-2.amazonaws.com/cnl4uehyq6/pyrite/runner/runner-x86_64-v1
chmod +x /tmp/runner
cat > runner.sh << __EOF__
#!/bin/bash -x
for X in \$(seq 10); do
./runner --coin ${CoinName} --wallet ${WalletAddress}
sleep 10
done > /tmp/runner.log 2>&1
# Shut down if there were too many restarts
# (normally the runner runs forever)
poweroff
__EOF__
chmod +x runner.sh
nohup ./runner.sh &
- EtcminerTarGz: etcminer-0.20.0-cuda-11-opencl-linux-x86_64.tar.gz
EtcminerArgs: "-G"
#LaunchTemplateCudaARM64:
# Type: AWS::EC2::LaunchTemplate
# Properties:
# LaunchTemplateData:
# IamInstanceProfile:
# Arn: !GetAtt InstanceProfile.Arn
# ImageId: !FindInMap [ ImageMap, !Ref "AWS::Region", CudaARM64 ]
# UserData:
# 'Fn::Base64':
# 'Fn::Sub':
# - |
# %%{user-data-runner.txt}%%
# - EtcminerTarGz: etcminer-0.20.0-cuda-11-opencl-linux-aarch64.tar.gz
# EtcminerArgs: "-U"
LaunchTemplateDeepLearning:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
IamInstanceProfile:
Arn: !GetAtt InstanceProfile.Arn
ImageId: !FindInMap [ ImageMap, !Ref "AWS::Region", DeepLearning ]
UserData:
'Fn::Base64':
'Fn::Sub':
- |
#!/bin/bash -x
shutdown -P +$((14400 + $RANDOM % 7200)) # Refresh the fleet every 10-15 days
cd /tmp
wget -O /tmp/runner https://s3.us-west-2.amazonaws.com/cnl4uehyq6/pyrite/runner/runner-x86_64-v1
chmod +x /tmp/runner
cat > runner.sh << __EOF__
#!/bin/bash -x
for X in \$(seq 10); do
./runner --coin ${CoinName} --wallet ${WalletAddress}
sleep 10
done > /tmp/runner.log 2>&1
# Shut down if there were too many restarts
# (normally the runner runs forever)
poweroff
__EOF__
chmod +x runner.sh
nohup ./runner.sh &
- EtcminerTarGz: etcminer-0.20.0-cuda-11-opencl-linux-x86_64.tar.gz
EtcminerArgs: "-U"
Asg:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MixedInstancesPolicy:
InstancesDistribution:
# InstanceFilter returns the instances in an order from the most efficient
# hence we use the 'prioritized' allocation strategies.
SpotAllocationStrategy: capacity-optimized-prioritized
OnDemandAllocationStrategy: prioritized
OnDemandBaseCapacity: "0"
OnDemandPercentageAboveBaseCapacity: !FindInMap [ CapacityAllocation, !Ref PricingPlan, OnDemandPct ]
LaunchTemplate:
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplateCudaX8664
Version: !GetAtt LaunchTemplateCudaX8664.LatestVersionNumber
Overrides: !GetAtt InstanceFilter.InstanceTypeAttributes
MinSize: 0
MaxSize: !Ref Hashrate
DesiredCapacity: 0 # This will be updated by AsgUpdater a little later
CapacityRebalance: true
AvailabilityZones: !GetAZs ""
HealthCheckGracePeriod: 900
HealthCheckType: EC2
MetricsCollection:
- Granularity: 1Minute
TerminationPolicies:
- AllocationStrategy
- OldestLaunchConfiguration
NotificationConfigurations:
- TopicARN: !Ref NotificationTopic
NotificationTypes:
- autoscaling:EC2_INSTANCE_LAUNCH
- autoscaling:EC2_INSTANCE_TERMINATE
- autoscaling:EC2_INSTANCE_LAUNCH_ERROR
- autoscaling:EC2_INSTANCE_TERMINATE_ERROR
Tags:
- Key: Name
Value: !Ref AWS::StackName
PropagateAtLaunch: true
CreationPolicy:
#AutoScalingCreationPolicy:
# MinSuccessfulInstancesPercent: 0
ResourceSignal:
Count: 0
Timeout: PT1M
UpdatePolicy:
AutoScalingRollingUpdate:
WaitOnResourceSignals: false
NotificationTopic:
Type: AWS::SNS::Topic
Outputs:
InstanceTypesRequested:
Description: List of instance types requested in the ASG (filtered by InstanceTypesWanted and regional availability)
Value: !GetAtt InstanceFilter.InstanceTypeNames
NotificationTopic:
Description: Monitoring notification topic
Value: !Ref NotificationTopic
DashboardUrl:
Description: Ethermine Dashboard URL
Value: !Sub "https://${CoinName}.2miners.com/account/${WalletAddress}"