How To: Run an Ethereum Node on AWS

Mercury Protocol
mercuryprotocol
Published in
4 min readDec 14, 2017

Dev highlights of this week

  • High volume rewards handling – uses an AWS SQS queue to retry any reward that fails
  • Upgraded to the latest go ethereum 1.7.3
  • Upgraded to Web3J 3.1 to make use of the new status flag from the Byzantium fork of Ethereum (currently in QA)
  • Researching ways to reduce or eliminate Ethereum gas costs including Brave, Raiden, 0x, and IOTA

How To: Run an Ethereum Node on AWS

You’ve figured out how to run Geth (go-ethereum) to start interacting with the blockchain from your computer, but what happens if you want to run Geth on your server so that all of your clients can connect to it as well? In our case, we wanted all of our Android, iOS, and Web clients to be able to interact with Ethereum without having to run an entire node themselves, and we wanted to leverage the security benefits of running our own node on a cloud service like AWS. This guide will walk you through firing up a Geth node on an AWS EC2 instance from a Mac, and assumes some knowledge of AWS and Ethereum.

Prerequisites

Make sure you have Homebrew installed, then install AWS Command Line Interface by entering the following in a terminal window.

brew install awscli

Configure AWS Credentials

You’ll need to create a key pair, security group, and access key before you start. Make sure to download the keypair file that is generated on creation. Before creating the keypair, ensure the region in the upper right corner matches the region you specify in the configure step below. We’ve selected Ohio (us-east-1) to keep costs down. We’ve selected json as the default output format, but you can output in whatever format fits your project best.

aws configureAWS Access Key ID [None]: <YOUR_ACCESS_KEY_ID>
AWS Secret Access Key [None]: <YOUR_SECRET_ACCESS_KEY>
Default region name [None]: us-east-1
Default output format [None]: json

For more information, consult the AWS Documentation.

Create EC2 Instance

Now, let’s create the EC2 instance where our node will run. We’ll use the most recent stable Ubuntu AMI with hardware virtualization and SSD volumes for performance.

The t2.medium will give us just enough general purpose computing power to run our node, but you may want to look for another instance type if you want to increase your memory or compute power.

We’ll tag the host just to make it stand out if we’re looking at the AWS Console, and write the resulting JSON to a file so we can refer to it later.

aws ec2 run-instances \
--count 1 \
--image-id ami-aa2ea6d0 \
--instance-type t2.medium \
--key-name <YOUR_KEY_NAME> \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Test-Geth-01}]' \
--associate-public-ip-address \
> geth-instance.json

The only thing you need to modify in the above snippet is <YOUR_KEY_NAME>. This needs to match the name you gave the keypair in the previous step, excluding the .pem extension, geth-keypair for instance.

SSH Into Your Instance

In order to SSH into our instance, we will need the public DNS name.

1. Get the instance id with

grep InstanceId geth-instance.json

2. Then, using the output, run

aws ec2 describe-instances \
--instance-ids <YOUR_INSTANCE_ID> \
--query 'Reservations[*].Instances[*].{publicdns: PublicDnsName}'

If this doesn’t return anything right away give it a minute, the public DNS name may not be assigned to this instance yet.

3. Now using your public DNS name, SSH in

Once you have your public IP ready to go, SSH into your instance with your downloaded keypair file. Make sure you open up port 22 in your security group! For more information on setting up your SSH client and configuration, see Amazon’s Connecting to Your Linux Instance Using SSH.

ssh -i /path/to/<YOUR_KEY_NAME>.pem ubuntu@<YOUR_PUBLIC_DNS_NAME>

Connect to Ethereum

1. Once logged into the instance, install Ethereum for Ubuntu

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y ethereum

2. Fire up your Geth node

Do this just like you would on a local machine. In this case let’s point it to the Rinkeby test network. This terminal window will now display all Geth logs for the Rinkeby network.

geth --rinkeby

3. Interact with Rinkeby

Open another terminal window and run the same ssh command from above, and attach it to Geth.

geth attach /home/ubuntu/.ethereum/rinkeby/geth.ipc

You should see the following.

Welcome to the Geth JavaScript console!instance: Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9
modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0
personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
>

You can now interact with Geth just like you would a local instance! It will take some time to sync with the Ethereum blockchain. You can check syncing status with:

> eth.syncing
{
currentBlock: 1083241,
highestBlock: 1410116,
knownStates: 2890515,
pulledStates: 2890515,
startingBlock: 0
}

Once currentBlock reaches highestBlock syncing has completed, and if you run the command again you should see:

> eth.syncing
false

You can also check things like peerCount to see how many nodes you are directly connected to.

> net
{
listening: true,
peerCount: 12,
version: "4",
getListening: function(callback),
getPeerCount: function(callback),
getVersion: function(callback)
}

Note: You can point to the Ethereum Mainnet by simply omitting rinkebyfrom steps 2 and 3.

Cleaning Up

1. Exit the Geth JavaScript console with

> exit

2. Terminate Geth node with

Ctrl-C

4. Log out of your instance with

exit

3. Tear down EC2 instance with

aws ec2 terminate-instances --instance-ids <YOUR_INSTANCE_ID>

Share your thoughts with us in any of the community channels linked below!

Connect

Slack
Telegram
Twitter
Reddit
Facebook
LinkedIn

Learn more about the Mercury Protocol
Read the Mercury Protocol whitepaper

--

--