How to deploy Ruby on Rails Application on Amazon EC2

Hello guys,

I am using Ubuntu 10.04, Rails 2.3.8 and Ruby 1.8.7. I want to deploy my rails application on Amazon EC2. But before that we have to create instance on Amazon and configure it. So I will show you how to do this.

First of all I am not using ec2onrails gem because it isn’t maintained regularly and supports old AMI . Then I assume that you are somewhat familiar with Amazon terms and you have account there. If not then please do it first.

After creating account and undestanding Amazon terms you need to have following things which you can find from Security Credentials tab from Here.

1) Amazon Account Number
2) Access Key ID
3) Secret Acsess Key
4) Amazon x.509 Certificate
5) Private Key Certificate

Now download developer tools from Here and then extract it and put it in some folder.

I put certificates and developer tools in /home/pulkit/cert folder.

now install Java if you don’t have.

So after downloading all necessary things, let’s start for setup.

# Set Java Path
1) export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
2) export PATH=$PATH:$JAVA_HOME/bin

# Set Private Key
3) export EC2_PRIVATE_KEY=/home/pulkit/cert/pk-PUL4MOWVQI4IOOKRV3BRJC2MHXJ2KKIO.pem

# Set Certificate
4) export EC2_CERT=/home/pulkit/cert/cert-PUL4MOWVQI4IOOKRV3BRJC2MHXJ2KKIO.pem

# Set api-tools
5) export EC2_HOME=/home/pulkit/cert/ec2-api-tools-1.3-62308
6) export PATH=$EC2_HOME/bin:$PATH

# add keypair to Amazon
# Save it in /home/pulkit/.ssh folder with name “id_rsa-rails-keypair”
7) ec2-add-keypair rails-keypair

# create instance by choosing AMI
# There are lots of AMI available in the market. Choose it as per your requirement. To see list of AMI and it’s details, visit Here.
8 ) ec2-run-instances ami-66e2130f -k rails-keypair

# See details of instance
# change i-9f57h52f3 with your instance id. You will get it when you will run above command.
9) ec2-describe-instances i-9f57h52f3

# Allow Port 22 and 80
# Unfortunately If you will get error
# “Client.InvalidPermission.Duplicate: The permission ’0.0.0.0/0-1-22-22′ has already been authorized on the specified group” for ec2-authorize default -p 22
# OR
# “Client.InvalidPermission.Duplicate: The permission ’0.0.0.0/0-1-80-80′ has already been authorized on the specified group” for ec2-authorize default -p 80
# it means that your ports are already allowed. You can move to next steps.
10) ec2-authorize default -p 22
11) ec2-authorize default -p 80

# If you are using git repository then copy your id_rsa.pub(github key) to Amazon Instance.
# As per your instance, username can be different(root or ubuntu). Make sure that you set name as “authorized_keys2″ not “authorized_keys”. Because “authorized_keys” is already there.
12) scp -i ~/.ssh/id_rsa-rails-keypair ~/.ssh/id_rsa.pub ubuntu@ec2-XX-XX-XXX-XXX.compute-1.amazonaws.com:.ssh/authorized_keys2

# login to Amazon Instance using SSH command.
13) ssh -i /home/pulkit/.ssh/id_rsa-rails-keypair ubuntu@ec2-XX-XX-XXX-XXX.compute-1.amazonaws.com

Now you should be in Amazon Instance. Install all necessary packages and gems as per your requirements.

In next post I will show you how to deploy rails application using capistrano on Amazon Instance.

Thanks & Regards,
Pulkit J. Pancholi

Reference : http://blog.dhavalparikh.co.in/2011/01/deploying-rails-application-on-amazon-ec2/

About these ads

About pulkitengg055
Hi I am Pancholi Pulkit.

2 Responses to How to deploy Ruby on Rails Application on Amazon EC2

  1. Pablo says:

    Hello pulkitengg055, i’ve been reading your post it is very interesting but… the content is not accord withe the subject of that, you announce that the post shows hot to deploy a RoR on AWS (EC2), but it’s no true, you only describe the ways to create an instance on ec2, how can in deploy a ror app? i’ve followed or your steps and it works, but, i don’t know how to use capistrano to deploy the application on my server.

    Regards.

    • pulkitengg055 says:

      Hi Pablo,

      May be you are right. The title may confuse you. Actually I was planning to share deployment steps in my next post. Meanwhile you can go through capistrano docs. It’s not that much tough! To use it, you are suppose to create deploy.rb file in your config folder. More or less It will be like this

      If you have any more questions feel free to contact me.

      Pulkit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: