Wiki
Social Graphs and Interactions

Amazon EC2
Page last edited by Claire Elizabeth Joyce (celjoy) 08/10-2014

This page contains instruction for setting up an Amazon EC2 instance for running your bot. Amazon's machine is free of charge for a year, and is a great little computer with one processor, 1GB of RAM and 8GB of storage space, which should be more than enough for the course. And, most importantly it will allow you to run the bot code 24/7, without having to keep your computer running and connected to the internet.

 

STEP 1: Creating an instance

  1. Go to AWS Free Tier webpage and press Get Started Today
  2. Open a new Amazon account, register with your credit card (nothing will be charged)
  3. Under Compute & Networking select Amazon EC2 and then Launch Instance
  4. Select an Ubuntu Server 14.04 and in the next screen click Review and Launch, then Launch
  5. When prompted about key pair select "Create a new key pair" and name it for example "ec2 keypair", then download it.
  6. Click Launch instances
  7. In the next screen click "View instances" to review the list of your machines

 

STEP 2: Configuring the instance

In this step we will install all necessary software on your machine to make sure it can host a twitter bot.

  1. Follow the instructions from http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html for your own operating system to connect to your machine
  2. Once you have connected paste this command into console to download Anaconda Python distribution:
    wget http://09c8d0b2229f813c1b93-c95ac804525aac4b6dba79b00b39d1d3.r79.cf1.rackcdn.com/Anaconda-2.0.1-Linux-x86_64.sh
  3. Paste this into console to install it:
    bash Anaconda-2.0.1-Linux-x86_64.sh
  4. You can press q when you are done reading terms and conditions.
  5. Say yes to license terms, then confirm the default location and say yes to prepending anaconda location to your bashrc file
  6. Now disconnect from your machine by typing exit
  7. Connect again and perform the following commands:
    sudo apt-get install python-pip
    pip install twitter
    sudo apt-get install git
    sudp apt-get install sqlite3
    git clone https://github.com/ptwobrussell/Mining-the-Social-Web-2nd-Edition.git
     
  8. Congratulations, your machine is ready to host your bot!

 

STEP 3: Configuring the logging

In this step we will set up a logger that will keep track of your bot's actions: the followers and friends, and the tweets your bot creates.

  1. Log into your EC2 instance and move to the ubuntu user home folder:
    cd /home/ubuntu/
  2. download the setup file:
    wget http://raman.imm.dtu.dk/pisa/twitter/settings.py -O /home/ubuntu/settings.py
  3. Use your favorite editor to edit the setup.py file and fill in the gaps (use an integer for user_id, for example USER_ID = 123123)
  4. Download the logging script:
    wget http://raman.imm.dtu.dk/pisa/twitter/runner.sh -O /home/ubuntu/runner.sh
  5. Give the logging script run permissions:
    chmod +x runner.sh
  6. Run it once to see if everything works:
    ./runner.sh
  7. After running, activity.log file will be created in the home folder, you can inspect it to see if everything is fine.
  8. If you get authentication errors, make sure that the information in settings.py is correct.
  9. Edit your crontab so that the runner.sh is run every hour, for example by adding this line:
    0 * * * * /home/ubuntu/./runner.sh

 

 

Support: +45 45 25 74 43