|
Resources
Articles and Tutorials
Hosting Facebook Applications on Amazon EC2
 |
Popular social networking applications are often victims of their own success, creating a surge of traffic to the application hosts. In this tutorial, Facebook application developer Nikki Everett shows how to take advantage of Amazon EC2's computing power for Facebook applications.
| AWS Products Used: |
Amazon EC2 |
| Language(s): |
PHP, Ruby |
| Date Published: |
2007-11-09 |
|
|
 |
By Nikki Everett
In this tutorial, I will go through the basic steps to teach you how to host a Facebook application using the Amazon EC2 and Amazon S3 services. I use my application, Quote Boat, as an example.
Getting Started
Read the Getting Started Guide. I'll follow the general steps in that guide, adding in what I think is missing or relevant, and of course, telling you how to do it Facebook-style.
Setting up the Tools
- Go to aws.amazon.com and sign up for an Amazon EC2 account. You're going to get an x.509 certificate and a private key file. For the love of God, don't give these things out to strangers in the street. Save them in a special place, like ~./ec2.
- Next, download the tools.The tools require java to run, so make sure you have Java 5 (Mac OS X users, this should already be on your computer). You'll also need an SSH client.
Note: There is a difference between the AMI command line tools and the API bundling tools. One is a set of command line utilities written in java that contain shell scripts for accessing and describing AMIs and instances. The other is a set of Ruby scripts for bundling up your instance and producing a shiny new AMI. Installing the bundling tools on your Macs, while not impossible, is really annoying because the native file format--.rpm--is not supported by that machine. If you look carefully, you will notice that you only need the command line utilities on YOUR machine and the Ruby tools live on the EC2 machines. You are not going to be doing any bundling on your machine, so don't fret over how to keep Real Player from trying to open your scripts. Follow the instructions on the AWS command line tools tutorial.
- Set up the tools. This requires putting the tools in your path (This is also in the Getting Started Guide). Make sure you edit your .bashrc file so that your environment variables persist...some of you might know this, but probably some of you do not. Java is a little funky on the Mac. You probably need to set the variable to /System/Library/Frameworks/JavaVM.framework/Home/. It's not obvious on the guide.
Running an Instance
You're almost ready to rock and roll. Refer to the guide for full instructions. The basic outline is as follows (
Amazon's guide has these same directions in a slightly different order; this is just the order that seemed clearest to me):
- Generate a keypair.
Open up a terminal window and type ec2-add-keypair. Open a text editor on the command line and paste the key from "start rsa private key" to "end rsa private key", inclusive. Save it as rsa_id-gsg-keypair. Then you need to change the file permissions on your key, otherwise Amazon will squawk at you when you try to run instances. Staying on the command line, type chmod 600 id_rsa-gsg-keypair. This gives you and only you the power to read and write to your key file.
- Authorize traffic on your instances to ports 80 and 22 (HTTP and SSH, respectively) with the commands ec2-authorize default -p 22 and ec2-authorize default -p 80.
The basic idea behind this part is that every instance you run is a member of some authorization group that has certain, well, authorizations. Amazon starts you off with an authorization group with no authorizations (called "default"), and you have to manually add them in.
- Bring up a list of available AMIs.
Type ec2-describe-images -o self -o amazon on the command line. This will bring up your images and Amazon's images.
- Run an instance of an AMI.
Once you find an image you want to run, type ec2-run-instances -k gsg-keypair [AMI] (I use ami-25b6534c, which is a basic LAMP stack using Fedora Core 4). This will return to you metadata about the image, such as the reservation number, your amazon id, and the instance number. You need the instance number in order to access the instance. The instance number is identified by i-[some number]. Next type in the command ec2-describe-instances [instance id]. this will give you the instance's public hostname. To log in to the instance, type ssh -i id_rsa-gsg-keypair root@[public hostname].
Modifying Your Instance, Facebook-Style
This requires only a few tweaks. Here are the things you need to consider:
Bundling the Instance
At this point, you are ready to bundle up your instance as an AMI. scp your app's files and the client library (php or java) you want to use to the instance, follow Amazon's bundling instructions (notice a trend here?), fill out your app settings on Facebook, and take 'er out for a spin.
And now...You're done! Launch your app, get famous, run a hundred and one instances, pay for what you use. Keen!
Resources
Nikki Everett is a developer and writer for Renkoo, the creators of Booze-Mail and Haikoo Zoo. She is also one of those rare employed philosophy majors.
|
Posts:
1
Registered:
5/8/09
|
|
|
|
|
Thank you!!, Nov 17, 2007 5:44 PM
Reviewer: joel1198
This is great!! Thank you for taking the time to help your Facebook developers colleagues.
|
|
Thanks for the link :), Nov 27, 2007 8:50 AM
Reviewer: Scott A Patten
The permanent link for the blog entry on updating dynamic DNS on EC2 is http://spattendesign.com/2007/10/10/updating-dynamic-dns-on-amazon-ec2.
Scott Patten
http://spattendesign.com
|
|
Persistant Database Data?, Jan 25, 2008 1:28 PM
Reviewer: "boxcarwilli"
First, I appluad you for this writeup and AMI's as I'm currently evaluating this. However, you dont elaborate at all about how when an EC2 instance goes down, so does all of your data and any changes you made to that instance. How are you dealing with that?
Also, one could use WeoCeo instead of the DynDNS option you touched on. WeoCeo allows you to automatically scale up and down your instances based on CPU usage, and, takes care of the DNS issues as well.
|
|
Tips on hosting a public Web site on Amazon EC2 and S3, Mar 13, 2008 4:18 PM
Reviewer: Rajiv Pant
Given the difficult to predict viral nature of traffic and usage growth on social networking applications like Facebook applications, AWS is a great platform for hosting social networking applications.
I found this document useful in porting my personal Web site http://www.rajiv.com/ to AWS.
Here are some tips on hosting a public Web site on Amazon EC2 and S3 from my experience:
http://www.rajiv.com/blog/2008/02/04/amazon-ec2/
|
|
If you need PHP 5.2.x or just JSON, Apr 17, 2008 7:05 PM
Reviewer: appmail
This is definitely a good start but I spent a fair time trying to gey my PHP in order.
The first thing you need to do is get everything updated.
yum update
To get JSON support in your PHP
yump install php-json
If PHP 5.0.4 is not cutting it for you and you want PHP 5.2
cd /etc/yum.repos.d
wget http://remi.collet.free.fr/rpms/remi-fedora.repo
yum --enablerepo=remi update mysql
yum --enablerepo=remi update php
apachectl restart
Enjoy!
|
|
very helpful - but here are more details, Feb 19, 2009 7:12 PM
Reviewer: Luke Barrington
Thanks for this information! I found it very useful in getting my Facebook game, Herd It, hosted on AWS (www.herdit.org).
However, even with this page, there are still a lot of details that are left for the reader to figure out, particularly regarding the Elastic DNS. I've tried to give a more complete description on my blog:
http://doubtfulsound.blogspot.com/2009/02/herd-it-on-amazon-web-services.html
Thanks again,
Luke
|
|
|
|
 |
|
|