Bitcoin mining with Amazon Web Services

This article was originally published via Tumblr.

Arriving a little bit late to the Bitcoin party I was intrigued by the mining process so thought I would give it a go on a lazy afternoon with help from this blog post. Rather than tie up my home PC or commit to long term hosted mining contracts I used Amazon Web Services to provision a suitable machine for a few cents an hour. Thanks to the availability of suitable Bitcoin miners on GitHub the process is remarkably simple to get up and running.

If you want to know the basics of Bitcoins please refer to this article.

There are essentially two approaches to mining Bitcoins, which in essence is trying to solve a complex mathematical problem (which are getting progressively more difficult with time). On solving a problem or block a reward is given of 25 Bitcoins (BTC). You can try to solve a block yourself in which case you get the full reward of 25 BTC if you happen upon a solution (currently worth an approximate $20000 using the exchange rate from As the work the computers do is akin to guessing a lottery number, the faster the computer the better chance of guessing the right number and solving the block (source).

The alternative to solitary mining is to join a mining pool where you are rewarded for the portion of work you complete in finding a block. There are a number of mining pools in existence with perhaps the best known being Slush’s pool at which is the pool we will use for the remainder of this article.

If you have a few months to spare, free electricity, the computer to make it worthwhile and are feeling particularly lucky, the first option might be feasible. Otherwise, join a mining pool to guarantee a reward (albeit likely very small).

Before you read on and try this yourself do not expect to make any money from doing this via this approach. I earned 0.00003643 BTC for a few hours work - not even close to an amount that you can withdraw and AWS costs were many times higher. Sadly, the complexity of the problems are now far beyond this approach being cost effective but if you want to try…

Firstly signup for a mining pool such as Slush’s pool and you’ll be given a login and password which you’ll need later to connect to the pool and start mining.

Next, assuming you already are using AWS login to the EC2 control panel and launch the community AMI ami-12b6477b. Launch the GPU instance type cg1.4xlarge. This is a StarCluster machine that has two NVIDIA Tesla “Fermi” M2050 GPUs (GPU mining is faster than CPU mining). I launched this cg1.4xlarge as a spot instance to keep the costs low ($0.350 per hour at the time of writing) accepting all the defaults and downloading the generated private key. Once the machine is up and running log in to the machine using SSH as the root user using the private key you downloaded and run the following commands which essentially just clone a mining repo and start mining on the two available GPUs. You’ll need to insert the username and password from your Slush’s mining pool account in the links below.

yum -y install git
pip-2.6 install pyserial
env GIT_SSL_NO_VERIFY=true git clone
cd poclbm
nohup python26 -d0 http://login:[email protected]:3333 \> bitcoin1.txt &
nohup python26 -d1 http://login:[email protected]:3333 \> bitcoin2.txt &

I used the nohup command to run the mining processes in the background, outputting to a text file in the current directory. To see the progress you can simply tail the files to monitor the progress and any errors in your configuration. Then just sit back and watch the BTC roll in on the ‘My Account’ section of the website which will provide you real-time feedback of your mining operation! As a benchmark I was able to get a sustained hash rate of around 100 Mh/s from both GPUs.

As I mentioned above, whilst this AWS-hosted solution is a nice practical exercise in mining Bitcoins it’s unlikely to ever be profitable (profitability is ultimately dependent on the Bitcoin price and instance spot price). Rather than mining, it is of course possible to purchase Bitcoins with a number of sites dedicated to this process. Whilst most sites require some form of personal verification, if you are in Canada and want to pick up a small amount of Bitcoins, the service will allow you to purchase up to 0.08 BTC every 24 hours using your Canadian phone number (you are sent a verification code to your mobile).

As the mining operations become more industrial in nature, an interesting trend and one that is likely to continue in 2014, is the use of dedicated cloud services for mining (also known as cloud hashing). Some notable services include:

Whilst these services offer greater computing power than you are likely to be able to provision on your own they also require some form of long term commitment and offer no guarenteed returns.

Whilst I am ultimately still skeptical about Bitcoins (not least as though they are limited in supply the amount of virtual currency is certainly limitless), it’s an undeniably fascinating topic and I’m certainly keeping hold of my hard earned Bitcoins for a while at least.

Note: At the time of writing this 1 BTC = $750 USD