In my previous post about setting up an on-demand cloud-based chess engine, I gave my ideas about how to get this remote server up and running. In this post I’ll talk about how to actually connect and use that engine.

Remote Proxy

The first thing you will need is a way to connect to the remote server from your chess database. I’ll be using Chessbase as an example, but I think most of them will work the same way.

I wrote a chess engine proxy called SSHEngine. This lets Chessbase use the SSHEngine.exe file as the engine, but behind the scenes that program is looking at a configuration file and connecting to the remote engine over SSH.

Ever Changing IP Address

The need for this SSHEngine setup is now more clear. Because I am starting the remote server only when I need it, and stopping it when I am done, the IP address of the host changes every time. I need to update the configuration file every time before I try to connect.

For an additional cost in AWS, you could set up an Elastic IP that reserves an IP address for you. But one of my goals was to keep costs down, so I just update the configuration file every time.

Sounds complex? Not when I just wrote a script that does it for me…

The Old and Slow Way of Setup

Previously, when I wanted to use the remote chess engine, I would do this:

  1. Log into the AWS Console
  2. Go to my EC2 Dashboard
  3. Start the Instance
  4. Copy the new IP Address
  5. Open the SSHEngine configuration file
  6. Replace the IP Address
  7. Save the file
  8. Launch the engine from Chessbase

Then when I was done:

  1. Log into the AWS Console again (if I was logged out)
  2. Go to my EC2 Dashboard
  3. Stop the Instance

The Better Way - an Automated Script

Since this is doing the same thing every time, I figured I would just write a script to do it for me.

Now the steps are:

  1. Run a script to start the instance
  2. Run a script to update the configuration file
  3. Launch the engine from Chessbase

And when I am done:

  1. Run a script to stop the instance

The script is written in python and can be found here:

EC2 Instance Manager script

Now getting the instance running and SSHEngine configured only takes a few seconds, less time than it takes for Chessbase to startup.

Automatic Shutoff

One risk with this approach is forgetting to stop the instance when you are done with it. Since you pay by the minute, if you forget to shut it down you will continue to pay for the running server.

I set up an AWS Lambda function that automatically shuts down the instance every night at midnight, just to be safe. Here is the tutorial to schedule the stopping of an EC2 instance that I used.