AWS Elastic Load Balancer Tutorial

1
Jun
19

We’ve been using the new Amazon Load Balancers (ELB) for Socialmod, and since there’s not much information out there on the subject, I thought a blog post would be in order.

The load balancers are charged at $0.025 per hour, plus $0.008 per GB of data transferred through them. Personally I think this is very reasonable.

They’re  hardware based, and can balance both HTTP and TCP traffic. This means you can balance both the traffic to the web server, and the database traffic (although there are issues with the latter that I’ll talk about later).

Some of the following instructions are specific to OSX/Linux, check the docs for information about Windows.

Setting up the tools.

Download the tools from Amazon, unzip them and place them somewhere logical (in your home directory for example).

Edit your .bash_profile file (or .profile), adding the following line:

export ELB_HOME=~/path/to/elastic_load_balancing
export PATH=$PATH:$ELB_HOME/bin

If you’re not using EC2, you’ll have to go through the extra step of creating/downloading a private key, and adding EC2_CERT/EC2_PRIVATE_KEY to  your bash file.
I’ll assume you are, since you can’t use ELB with any other server setup.

Create the load balancer.

Execute the following command. Only include the zones you actually have instances in – I made the mistake of including extra which meant the balancer kept on droppingn requests.

elb-create-lb  default --zones us-east-1a --listener "protocol=http, lb-port=80, instance-port=80"

You’ll be given the URL of your new load balancer in return which you’ll need for configuring the DNS.

Register instances.

Now to actually register any EC2 instances with the load balancer.

elb-register-instances-with-lb default --instances i-12345678

If you navigate to the load balancer’s URL you’ll probably see an Apache “It Works!” sign.
You could add the Load Balancer’s URL to your virtual host’s domain alias in order to actually see the web page.

Configure DNS.

Ok, so here comes the kicker – you can’t use ELB for the root of your domain. This is because the load balancers can only be referenced by a domain name, not an IP address. You can’t have a CNAME on the root of a domain – it has to be on a subdomain.configure ELB DNS

Amazon are busy adding this ‘feature’, but in the meantime you should forward everybody to a subdomain, such as ‘www’.

Here’s an example of an Apache rewrite condition that forwards everybody to www:

RewriteCond %{HTTP_HOST} ^socialmod.com$ [NC]
RewriteRule ^(.*)$ http://www.socialmod.com$1 [R=301,L]

Advanced Load Balancing

You can load balance your Mysql cluster – however ELB is outside Amazon’s firewall and isn’t integrated with it. This means that to load balance Mysql you need to open it up to the world and rely on strong credentials to keep your data secure, rather than firewall rules.

ELB can handle SSL traffic, just set the protocol to TCP and the port to 443 when you create the balancer. Currently, Elastic Load Balancing does not have SSL termination capability.


ELB is certainly in it’s infancy, but has been beta tested and is ready for production. I just hope that Amazon add ELB management to their AWS console.

Filed under: AWS

We’ve listened – pricing changes

1
Jun
0

Well, it just a few days after the public launch of Socialmod and we’ve had a lot of signups.

We’ve also had a lot of feedback, which is always very useful because ultimately you don’t know what your customers want, unless they tell you.

Generally we were getting the message that the limits on the plans were too low, people needed to do more moderation.

With that in mind we’ve increased the moderation limit on all the plans, apart from the Basic one, and made all the ‘Automated’ plans (including Mechanical Turk) $10 less.

Adding moderation to your Rails site in 5 minutes

31
May
0

This short tutorial will show you how to integrate Socialmod into Rails in a matter of minutes. This time we’re focussing on text moderation – future tutorials will tackle image and video moderation.

The general process goes likes this:

  • Comment (i.e. UGC text content) is created
  • A POST request is sent to Socialmod, with the text to be moderated and the Comment’s id
  • Moderator moderates text
  • A POST request is sent from Socialmod to your designated callback url with the moderators verdict
  • You then choose to hide/show that item depending on whether you’re doing pre/post moderation, and obviously the verdict.

Firstly, install the gem:

sudo gem install socialmod

Generate your Rails app, and add the gem to config/enviroment.rb;

config.gem "socialmod"

We need to configure the Socialmod library to use your api key.

config/initializers/socialmod.rb

Socialmod::Base.api_key = '00000000-0000-0000-0000-000000000000'

Now we’re going to generate the scaffolding for the Comment model, and install the state machine plugin:

script/generate scaffold comment body:text state:string
script/plugin install git://github.com/pluginaweek/state_machine.git
rake db:migrate

Now to implement the pending, passed and failed states on the Comment model:

app/model/comment.rb

class Comment < ActiveRecord::Base
  state_machine :initial => :pending do
    event :passed do
      transition [:pending, :failed] => :passed
    end

    event :failed do
      transition [:pending, :passed] => :failed
    end

    state :pending, :passed, :failed
  end
  named_scope :passed, :conditions => {:state => "passed"}
end

And now we’re going to add the Socialmod specifics to the Comment model.
After the comment is created, the comment text is sent to Socialmod.

app/model/comment.rb

after_create :create_on_socialmod
def create_on_socialmod
  Socialmod::Item::Text.create(
    :data => body,
    :custom_id => id
  )
end

Now generate the callback controller. Below you can see we’re finding the comment, and passing or failing it based on the callback’s verdict.

You’ll also notice we’re skipping the verify_authenticity_token method. We don’t need XSS protection here (since we’re checking the signature of the callback – verifying its identity).

app/controllers/callback_controller.rb

class CallbackController < ApplicationController
  skip_before_filter :verify_authenticity_token, :only => :index

  def index
    callback = Socialmod::Callback.new(params)
    unless callback.valid?
      return head(403)
    end

    comment = Comment.find(callback.custom_id)
    if callback.passed?
      comment.passed!
    else
      comment.failed!
    end
    head 200
  end
end

How does Socialmod know which callback url to use?
Well you need to specify it in the settings:

callback-url-settings

Unfortunately the callback aspect of it makes testing locally difficult – that’s something that should be tested in the staging environment.

And that’s really all there is to it. You can choose whether or not you want pre-moderation by showing/hiding comments in the pending state.
One nice touch you could add is to only show pending items to the users that created them, so they can get some instant feedback.

The next blog post will show you how to use images with Socialmod.

Filed under: Socialmod

Hello World!

30
May
2

We’ve just released Socialmod, a moderation tool that Tim’s dubbed ‘the Basecamp of moderation‘.

User Generate Content (UGC) is such a large part of the internet, and, if it’s to be associated with a brand, it really needs to be moderated.

A lot of companies develop their own moderation systems in house – a classic case of reinventing the wheel. Socialmod was developed so companies don’t have to put the time and money into developing their own.

Socialmod accepts images, videos and text. Additionally it’s got Twitter integration and can publish a ‘clean feed’ – great for award ceremonies and news events (like the UK Budget).

There are two main ways you can use Socialmod:

  • Use your own team (or a moderation company) to moderate your content
  • Use Mechanical Turk – a crowd-sourcing service

Both have their advantages and disadvantages, and are appropriate for different situations.

socialmod - ugc moderation

As for this blog, I hope to mirror it, in some ways, after the  37 Signal’s Signal vs. Noise blog – but with more of an emphasis on the business and development side of things.

Some of the blog posts coming up are:

  • Adding pre-moderation to a Rails site
  • AWS Elastic Load Balancing tutorial
  • US Companies for non-residents
  • LLC’s and Articles of Organization
  • Merchant Accounts

Subscribe to the RSS!

Filed under: Socialmod