Monthly Archives: November 2015

My Twitter Bot

Almost a year ago I wrote about putting a Twitter Bot On Heroku. A few months ago my bot stopped responding. This was about the time that Heroku changed their billing plans, but to be honest I don’t know why it went offline.

Today I moved it over to EC2, and I am going to lift the veil and reveal who my Twitter bot is.

EC2 Setup

I picked an Ubuntu image because I prefer Ubuntu over Centos/RHEL. This doesn’t need a lot of horsepower, so the free tier should be just fine. This is also just a silly twitter bot.

So let’s get the foundation in place:

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

And now we need to install ruby. I don’t like installing a ruby version manager on a server. This is a dedicated host, and I control the deployment environment. So I’ll just install ruby and gems at the system level.

tar -xzvf ruby-2.2.3.tar.gz
cd ruby-2.2.3/
sudo make install
sudo gem install bundler --no-rdoc --no-ri

Super. Now we can ruby.

The Code

You could do some fancy deploy with Docker, and I thought about doing that. But this is just a silly Twitter bot. So instead I have just a single standalone EC2 instance, and I’ll clone the repo.

Yes, I wrote a Taylor Swift Twitter Bot.

Change into the project directory and run sudo bundle to install the gems. Bundler will complain about running as root, but we don’t care. We are running with scissors on Twitter.

Make It Go

Now we just need to make this thing run, and do that in such a way that if the server reboots that it keeps running. We use an init.d script for that.

I put this simple script in /etc/init.d:

cd home/ubuntu/swift-bot-tay-tay
dotenv rake

I still have the Rakefile from the Heroku setup, and I put a .env file on the box with the credentials. This is a cheesy script, and there are no “environments” so the dotenv gem works just fine.

*Disclaimer: that may not, in fact, be a proper init.d script. I actually kicked the script off from the command line using nohup dotenv rake & and if the server bounces we’ll just see what happens. We are running with scissors, after all.


It’s fun to play with a completely ridiculous project. I’m also amazed how something as simple and silly as a twitter bot elicits as much of a reaction as it does. @SwiftBotTayTay has nearly 900 followers and regularly gets responses to her tweets. Most of them are positive, too.

That makes me smile.

Leave a Comment

Filed under programming, ruby