Skip to content

Instantly share code, notes, and snippets.

@shaunenslin
Last active March 3, 2022 07:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunenslin/76db65ede1187211c55d02dbcb6dbdea to your computer and use it in GitHub Desktop.
Save shaunenslin/76db65ede1187211c55d02dbcb6dbdea to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: '2010-09-09'
# https://bitcointalk.org/index.php?topic=4432704.0
Metadata:
RepoUrl: https://github.com/xmrig/
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Miner Configuration
Parameters:
- WalletAddress
- Coin
- Label:
default: Instance Configuration
Parameters:
- InstanceType
- InstanceAmi
- Label:
default: Networking Configuration
Parameters:
- VpcId
- SubnetIds
Parameters:
InstanceType:
Type: String
AllowedValues:
- g4dn.xlarge # 1 GPU Tesla T4 -- best value (cost/performance)
- g4dn.2xlarge # 1 GPU Tesla T4
- g4dn.12xlarge # 4 GPU Tesla T4
- g4ad.4xlarge
- g4ad.8xlarge
- p3.2xlarge # 1 GPU Tesla V100
- p3.8xlarge # 4 GPU Tesla V100
- p3.16xlarge # 8 GPU Tesla V100
Default: g4dn.xlarge
InstanceCount:
Type: Number
Default: 2
MaxValue: 5
SpotPrice:
Type: Number
Default: 18
WalletAddress:
Type: String
Description: Doge, Eth or ADA Wallet Address
Default: ""
Coin:
Type: String
Description: Either DOGE, ADA, ETH
Default: "SHIB"
VpcId:
Description: The VPC where this stack will be deployed
Type: AWS::EC2::VPC::Id
SubnetIds:
Description: The subnets where the instances will be deployed - at least 3 subnets!
Type: List<AWS::EC2::Subnet::Id>
Mappings:
# ImageId of 'Deep Learning AMI (Ubuntu 18.04) Version 36.0' in each region
RegionMap:
ap-northeast-1:
ImageId: ami-03b8cfea5460e4881
ap-northeast-2:
ImageId: ami-07e004f63a0cccdd3
ap-south-1:
ImageId: ami-02cb047909c100c3d
ap-southeast-1:
ImageId: ami-068f673b54015684e
ap-southeast-2:
ImageId: ami-0f558ede443627831
ca-central-1:
ImageId: ami-0ca5bba27cf7db8f0
eu-central-1:
ImageId: ami-01227276a4e5a4a31
eu-north-1:
ImageId: ami-080691999cd85e762
eu-west-1:
ImageId: ami-006ff58f5247c50eb
eu-west-2:
ImageId: ami-096a6497745975f89
eu-west-3:
ImageId: ami-0346672391424d8e5
sa-east-1:
ImageId: ami-048837a0bfc1ba1a6
us-east-1:
ImageId: ami-063585f0e06d22308
us-east-2:
ImageId: ami-01bd6a1621a6968d7
us-west-1:
ImageId: ami-05fbe06ba1b862ef6
us-west-2:
ImageId: ami-0bc87a16c757a7f07
SpotPriceMap:
g4dn.xlarge:
MaxPrice: 0.18
g4dn.2xlarge:
MaxPrice: 0.23
g4dn.12xlarge:
MaxPrice: 1.57
p3.2xlarge:
MaxPrice: 0.92
p3.8xlarge:
MaxPrice: 3.68
p3.16xlarge:
MaxPrice: 7.36
g4ad.4xlarge:
MaxPrice: 0.27
g4ad.8xlarge:
MaxPrice: 0.58
Resources:
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
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
IamInstanceProfile:
Arn: !GetAtt InstanceProfile.Arn
InstanceMarketOptions:
MarketType: spot
SpotOptions:
SpotInstanceType: one-time
MaxPrice: !FindInMap [ SpotPriceMap, !Ref InstanceType, MaxPrice ]
InstanceType: !Ref InstanceType
ImageId: !FindInMap [ RegionMap, !Ref "AWS::Region", ImageId ]
SecurityGroupIds:
- !Ref SecurityGroup
UserData:
'Fn::Base64':
'Fn::Sub': |
#!/bin/bash -x
cd /tmp
mkdir trex
cd trex
INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
wget https://trex-miner.com/download/t-rex-0.20.3-linux.tar.gz
tar xvfz t-rex-0.20.3-linux.tar.gz
rm t-rex-0.20.3-linux.tar.gz
echo ./t-rex -o kp.unmineable.com:3333 -a kawpow -u ${Coin}:${WalletAddress}.kawpow$INSTANCE_ID?ref=5ech-akw9 -p x > runner.sh
chmod +x runner.sh
nohup ./runner.sh &
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Ref AWS::StackName
VpcId: !Ref VpcId
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Ref AWS::StackName
MinerAsg:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
LaunchTemplate:
LaunchTemplateId: !Ref LaunchTemplate
Version: !GetAtt LaunchTemplate.LatestVersionNumber
MinSize: 0
MaxSize: !Ref InstanceCount
DesiredCapacity: !Ref InstanceCount
CapacityRebalance: false
VPCZoneIdentifier: !Ref SubnetIds
HealthCheckGracePeriod: 300
HealthCheckType: EC2
TerminationPolicies:
- ClosestToNextInstanceHour
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
NotificationTopic:
Type: AWS::SNS::Topic
Outputs:
NotificationTopic:
Description: Monitoring notification topic
Value: !Ref NotificationTopic
DashboardUrl:
Description: Doge Dashboard URL
Value: !Sub "https://unmineable.com/coins/${Coin}/address/${WalletAddress}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment