{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "AWS CloudFormation template for ethereum node deployment", "Parameters": { "KeyName": { "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance", "Type": "AWS::EC2::KeyPair::KeyName", "ConstraintDescription": "Can contain only ASCII characters." }, "InstanceCount": { "Description": "Number of instances to deploy", "Type": "Number", "ConstraintDescription": "Integers only" }, "ETHStatsServer": { "Description": "Ethstats server", "Type": "String", "Default": "t2.micro", "AllowedValues": [ "t1.micro", "t2.micro", "t2.small", "t2.medium", "m1.small", "m1.medium", "m1.large" ], "ConstraintDescription": "Must be a valid EC2 instance type" }, "ETHStatsPassword": { "Description": "Password to connect to ethstats server", "Type": "String", "ConstraintDescription": "String only" }, "InstanceType": { "Description": "WebServer EC2 instance type", "Type": "String", "Default": "t2.medium", "AllowedValues": [ "t1.micro", "t2.micro", "t2.small", "t2.medium", "m1.small", "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge", "c1.medium", "c1.xlarge", "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge", "g2.2xlarge", "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge", "i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge", "hi1.4xlarge", "hs1.8xlarge", "cr1.8xlarge", "cc2.8xlarge", "cg1.4xlarge", "i3.large", "i3.xlarge", "i3.2xlarge", "i3.4xlarge", "i3.8xlarge", "i3.16xlarge" ], "ConstraintDescription": "Must be a valid EC2 instance type" }, "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" } }, "Conditions": { "IsNVME": { "Fn::Or": [ { "Fn::Equals": [ "i3.large", { "Ref": "InstanceType" } ] }, { "Fn::Equals": [ "i3.xlarge", { "Ref": "InstanceType" } ] }, { "Fn::Equals": [ "i3.2xlarge", { "Ref": "InstanceType" } ] }, { "Fn::Equals": [ "i3.4xlarge", { "Ref": "InstanceType" } ] }, { "Fn::Equals": [ "i3.8xlarge", { "Ref": "InstanceType" } ] }, { "Fn::Equals": [ "i3.16xlarge", { "Ref": "InstanceType" } ] } ] } }, "Mappings": { "AWSInstanceType2Arch": { "t1.micro": { "Arch": "64" }, "t2.micro": { "Arch": "64" }, "t2.small": { "Arch": "64" }, "t2.medium": { "Arch": "64" }, "m1.small": { "Arch": "64" }, "m1.medium": { "Arch": "64" }, "m1.large": { "Arch": "64" }, "m1.xlarge": { "Arch": "64" }, "m2.xlarge": { "Arch": "64" }, "m2.2xlarge": { "Arch": "64" }, "m2.4xlarge": { "Arch": "64" }, "m3.medium": { "Arch": "64" }, "m3.large": { "Arch": "64" }, "m3.xlarge": { "Arch": "64" }, "m3.2xlarge": { "Arch": "64" }, "c1.medium": { "Arch": "64" }, "c1.xlarge": { "Arch": "64" }, "c3.large": { "Arch": "64" }, "c3.xlarge": { "Arch": "64" }, "c3.2xlarge": { "Arch": "64" }, "c3.4xlarge": { "Arch": "64" }, "c3.8xlarge": { "Arch": "64" }, "g2.2xlarge": { "Arch": "64" }, "r3.large": { "Arch": "64" }, "r3.xlarge": { "Arch": "64" }, "r3.2xlarge": { "Arch": "64" }, "r3.4xlarge": { "Arch": "64" }, "r3.8xlarge": { "Arch": "64" }, "i2.xlarge": { "Arch": "64" }, "i2.2xlarge": { "Arch": "64" }, "i2.4xlarge": { "Arch": "64" }, "i2.8xlarge": { "Arch": "64" }, "hi1.4xlarge": { "Arch": "64" }, "hs1.8xlarge": { "Arch": "64" }, "cr1.8xlarge": { "Arch": "64" }, "cc2.8xlarge": { "Arch": "64" }, "i3.large": { "Arch": "64" }, "i3.xlarge": { "Arch": "64" }, "i3.2xlarge": { "Arch": "64" }, "i3.4xlarge": { "Arch": "64" }, "i3.8xlarge": { "Arch": "64" }, "i3.16xlarge": { "Arch": "64" } }, "AWSRegionArch2AMI": { "ap-northeast-1": { "64": "ami-785c491f" }, "ap-northeast-2": { "64": "ami-94d20dfa" }, "ap-south-1": { "64": "ami-49e59a26" }, "ap-southeast-1": { "64": "ami-2378f540" }, "ap-southeast-2": { "64": "ami-e94e5e8a" }, "ca-central-1": { "64": "ami-7ed56a1a" }, "eu-central-1": { "64": "ami-1c45e273" }, "eu-west-1": { "64": "ami-6d48500b" }, "eu-west-2": { "64": "ami-cc7066a8" }, "sa-east-1": { "64": "ami-34afc458" }, "us-east-1": { "64": "ami-d15a75c7" }, "us-east-2": { "64": "ami-8b92b4ee" }, "us-west-1": { "64": "ami-73f7da13" }, "us-west-2": { "64": "ami-835b4efa" } } }, "Resources": { "ETHRPCSecurity": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "Enable Geth RPC Port", "SecurityGroupIngress": [ { "IpProtocol": "tcp", "FromPort": "8545", "ToPort": "8545", "CidrIp": "0.0.0.0/0" }, { "IpProtocol": "tcp", "FromPort": "22", "ToPort": "22", "CidrIp": { "Ref": "SSHLocation" } } ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "54b037ce-872c-458e-8876-ff95f9b58d1d" } } }, "LoadBalancer": { "Type": "AWS::ElasticLoadBalancing::LoadBalancer", "Properties": { "AvailabilityZones": { "Fn::GetAZs": "" }, "Listeners": [ { "LoadBalancerPort": "80", "InstancePort": "8545", "Protocol": "HTTP" } ], "HealthCheck": { "Target": "TCP:8545", "HealthyThreshold": "3", "UnhealthyThreshold": "5", "Interval": "30", "Timeout": "5" } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "4369026b-a90f-474b-8fcd-b636341ea415" } } }, "EC2Group": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { "AvailabilityZones": { "Fn::GetAZs": "" }, "MinSize": { "Ref": "InstanceCount" }, "MaxSize": { "Ref": "InstanceCount" }, "LoadBalancerNames": [ { "Ref": "LoadBalancer" } ], "LaunchConfigurationName": { "Ref": "LaunchConfiguration" } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "d509e6f2-dd24-460d-8532-e98791c13777" } } }, "LaunchConfiguration": { "Type": "AWS::AutoScaling::LaunchConfiguration", "Properties": { "ImageId": { "Fn::FindInMap": [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" }, { "Fn::FindInMap": [ "AWSInstanceType2Arch", { "Ref": "InstanceType" }, "Arch" ] } ] }, "InstanceType": { "Ref": "InstanceType" }, "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "VolumeSize": "80" } } ], "KeyName": { "Ref": "KeyName" }, "SecurityGroups": [ { "Ref": "ETHRPCSecurity" } ], "UserData": { "Fn::Base64": { "Fn::Join": [ "", [ "#!/bin/bash -xe\n", "apt -y update\n", "DEBIAN_FRONTEND=noninteractive apt-get -y upgrade\n", "apt install -y docker.io screen\n", "mkdir /ethereum\n", { "Fn::If": [ "IsNVME", { "Fn::Join": [ "", [ "mkfs.ext4 -F /dev/nvme0n1\n", "mount /dev/nvme0n1 /ethereum\n", "chmod a+w /ethereum/\n", "echo UUID=`sudo blkid -s UUID -o value /dev/disk/by-id/nvme-Amazon*` /ethereum/ ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab\n" ] ] }, "" ] }, "export INSTANCEID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)\n", "docker pull myetherwallet/docker-geth-lb:geth-instance\n", "/usr/bin/screen -m -d -S docker docker run -e WS_SECRET='", { "Ref": "ETHStatsPassword" }, "' -e WS_SERVER='", { "Fn::GetAtt": [ "EthstatsInstance", "PublicIp" ] }, "' -e INSTANCE_NAME=\"mew-geth-instance-$INSTANCEID\" -it -p 8546:8546 -p 8545:8545 -p 30303:30303 -v /ethereum:/root/.ethereum --restart unless-stopped myetherwallet/docker-geth-lb:geth-instance \n" ] ] } } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "61d5b9ec-16cf-48f4-8d7d-861cc7e781e7" } } }, "EthstatsInstance": { "Type": "AWS::EC2::Instance", "Properties": { "ImageId": { "Fn::FindInMap": [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" }, { "Fn::FindInMap": [ "AWSInstanceType2Arch", { "Ref": "InstanceType" }, "Arch" ] } ] }, "InstanceType": { "Ref": "ETHStatsServer" }, "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "VolumeSize": "15" } } ], "KeyName": { "Ref": "KeyName" }, "Tags": [ { "Key": "Name", "Value": "ETHStatsServer" } ], "SecurityGroups": [ { "Ref": "ETHStatsSecurity" } ], "UserData": { "Fn::Base64": { "Fn::Join": [ "", [ "#!/bin/bash -xe\n", "apt update -y\n", "apt install -y docker.io screen\n", "docker pull myetherwallet/docker-geth-lb:ethstats-instance\n", "/usr/bin/screen -m -d -S docker docker run -it -e WS_SECRET='", { "Ref": "ETHStatsPassword" }, "' -p 3000:3000 myetherwallet/docker-geth-lb:ethstats-instance\n" ] ] } } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "65efe09a-0f3e-48c2-a30a-84d0c993d132" } } }, "ETHStatsSecurity": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "Enable Geth RPC Port", "SecurityGroupIngress": [ { "IpProtocol": "tcp", "FromPort": "3000", "ToPort": "3000", "CidrIp": "0.0.0.0/0" }, { "IpProtocol": "tcp", "FromPort": "22", "ToPort": "22", "CidrIp": { "Ref": "SSHLocation" } } ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "fe827154-fdc1-463d-9b70-44c556d2c5ee" } } } }, "Outputs": { "URL": { "Description": "The URL of the node", "Value": { "Fn::Join": [ "", [ "http://", { "Fn::GetAtt": [ "LoadBalancer", "DNSName" ] } ] ] } }, "ETHStatsIP": { "Description": "IP address of the ethstats server", "Value": { "Fn::Join": [ "", [ "http://", { "Fn::GetAtt": [ "EthstatsInstance", "PublicIp" ] }, ":3000" ] ] } } }, "Metadata": { "AWS::CloudFormation::Designer": { "54b037ce-872c-458e-8876-ff95f9b58d1d": { "size": { "width": 60, "height": 60 }, "position": { "x": 250, "y": 180 }, "z": 1, "embeds": [] }, "4369026b-a90f-474b-8fcd-b636341ea415": { "size": { "width": 60, "height": 60 }, "position": { "x": -80, "y": 180 }, "z": 0, "embeds": [] }, "d509e6f2-dd24-460d-8532-e98791c13777": { "size": { "width": 60, "height": 60 }, "position": { "x": 20, "y": 180 }, "z": 0, "embeds": [], "isassociatedwith": [ "61d5b9ec-16cf-48f4-8d7d-861cc7e781e7", "4369026b-a90f-474b-8fcd-b636341ea415" ] }, "61d5b9ec-16cf-48f4-8d7d-861cc7e781e7": { "size": { "width": 60, "height": 60 }, "position": { "x": 140, "y": 180 }, "z": 0, "embeds": [], "isassociatedwith": [ "54b037ce-872c-458e-8876-ff95f9b58d1d" ] }, "65efe09a-0f3e-48c2-a30a-84d0c993d132": { "size": { "width": 60, "height": 60 }, "position": { "x": 140, "y": 50 }, "z": 0, "embeds": [], "isassociatedwith": [ "fe827154-fdc1-463d-9b70-44c556d2c5ee" ] }, "fe827154-fdc1-463d-9b70-44c556d2c5ee": { "size": { "width": 60, "height": 60 }, "position": { "x": 250, "y": 50 }, "z": 0, "embeds": [] } } } }