Tutorial – Ruby on Rails hosted on Amazon cloud

On November 23, 2010, in Technical, by Sanchit Garg

Enough said about RoR
Enough said about Amazon EC2

This tutorial is about deploying an ROR app over Amazon Cloud infrastructure. It will give a walk through on commands and concepts so that you can integrate Github, Amazon production env and your local development env for your ROR app. It assumes you already have an Amazon web services account and will finish up with having ROR server up and running on EC2.

  • Get Familiar – You need to know about most of the amazon products listed on their site. Each of the product has a specific functionality and you need to know them to understand the machinery. Here is the minimum set of products that you need to know: https://www.amazon.com/ec2. Make sure you understand the dashboard before you start playing around.
  • Install command line tools – Either you play around with the dashboard or use command line tools for better efficiency. There are numerous tutorials to learn them, I followed this one:
  • Create your instance - You need to choose an ami (amazon instance image) and deploy on EC2. There are lot of good tutorials that show how to do this. At the end of this step, you should have a running instance on amazon EC2 and should appear in the dashboard. Here are some pointers:
  • SSH to your instance – You will get a private key from amazon and you will have to use it to ssh to your instance.  Before you can ssh to your instance, you will need to open up security permissions at amazon side. For that, go to dashboard -> security groups -> default. Add another entry allowing ssh from all the IPs (0.0.0.0/0). Your command to ssh from your terminal will be something like this
    • ssh -i <path_to_private_key> ubuntu@domain-name
    • domain-name is the ‘public dns’ of your instance. You can read it on your dashboard -> Instances or by executing API command: ec2-describe-instances
    • I prefer to run ssh-add <path_to_priavte_key> which tells ssh to add the key permanently in its db and you can then simply run: ssh ubuntu@domain-name without worrying about private key option. (ssh-add -t 99999999 <path_to_priavte_key> to add it for long enough time)
  • Prepare the instance – Now you can access to your crude VM which has nothing but ubuntu (or OS as per your ami). Let us install the basic packages needed. There are lots of tutorials again. I referred following tutorials to prepare the VM and install rails, ruby and gem.
  • Clone source code – Now we will get our source code from git repository.
    • Get code: git clone https://gitUser:gitPasswd@github.com/repoUser/repo.git
    • Install dependencies: bundle install
    • README: Start other services such as sphinx, etc. mentioned in app’s READMEs
    • db initialization: rake db:create; rake db:migrate; rake db:seed
    • Git settings:
      • git config –global user.name “username”
      • git config –global user.email “emailid@xyz.com”
      • git config –global core.autocrlf input
  • Connect your development env to ec2 – I prefer to directly push my code from local environment to production environment. To achieve this, add production environment repository as a remote repository in your local development box.
    • git remote add ec2 ssh://<user>@<amazon-public-dns>/~<user>/<repo-path>
    • Now you can run git push ec2 master to push your code from your local environment to amazon production.
  • Start the server – Start your rails server on amazon VM (rails server) and test out if you can open http://public-dns-of-instance.com:3000 from your browser. Here are the next steps:
    • You will need to change the port from 3000 to 80. But 80 port (in fact any port < 1024) can only be opened by root. In this case, I do not want to run “sudo rails server” and hence I prefer configuring IPtables on amazon VM so that they forward all request at port 80 to port 3000. Here is the command:
    • sudo iptables -t nat -A PREROUTING -p tcp –dport 80 -j REDIRECT –to-port 3000
  • Set the Domain – Last step is to add your own domain name so that customers can open your application by the domain name you like. This is a little tricky part and you should understand what is elastic IP. After you understand the idea behind elastic IP, here is what you need to do.
    • Generate an elastic IP from your dashboard -> Elastic IPs. Bind that IP to your instance ID which is running your server. This maps your VM to a static IP (or elastic IP) that you just generated.
    • Go to your dns provider (e.g. godaddy.com) and configure your DNS settings there. Add this elastic IP as A name and allow 24 hours for your domain to get bound to the elastic IP. After that your web server is all configured.
  • Snapshot - Create a snapshot of your volume in the dashboard. You can create volumes out of this snapshot if anything goes wrong with your current one.

I will add more details on this. For now, have fun. Feel free to pour in questions, suggestions or comments.

Tagged with:  

Amazon Web Hosting – Free Tier Basics

On November 21, 2010, in Technical, by Sanchit Garg

Amazon Web Services recently broadcast a free tier for 1 year, where one will not be charged for a year and will get some basic functionalities free of cost. This tutorial describes the basics, what is free and how to start on hosting your web application over amazon cloud.
To begin with, what is available under the ‘free tier’ tag:
As part of AWS’s Free Usage Tier, new AWS customers can get started with Amazon EC2 for free. Upon sign-up, newAWS customers receive the following EC2 services each month for one year:

Free Tier
Source: http://aws.amazon.com/free/
  • 750 hours of Amazon EC2 Linux Micro Instance usage (613 MB of memory and 32-bit and 64-bit platform support) – enough hours to run continuously each month
  • 750 hours of an Elastic Load Balancer plus 15 GB data processing
  • 10 GB of Amazon Elastic Block Storage, plus 1 million I/Os, 1 GB of snapshot storage, 10,000 snapshot Get Requests and 1,000 snapshot Put Requests
  • 5 GB of Amazon S3 storage, 20,000 Get Requests, and 2,000 Put Requests
  • 30 GB per of internet data transfer (15 GB of data transfer “in” and 15 GB of data transfer “out” across all services except Amazon CloudFront)
  • 25 Amazon SimpleDB Machine Hours and 1 GB of Storage
  • 100,000 Requests of Amazon Simple Queue Service
  • 100,000 Requests, 100,000 HTTP notifications and 1,000 email notifications for Amazon Simple Notification Service

Few Deductions

  • Max hours in one month: 31 * 24 = 744 hours
  • The free package would normally cost around 700 Rs (15$) per month for instance alone and few bucks for other services such as Block storage (approx 0.4$ per month) or Amazon Simple Storage Service (approx 1$ per month, used for storing pictures, videos, etc.)
  • This cost gets minimized to 450 Rs (10$) per month if you reserve your instance for an year

Terminology

Micro Instance – Hardware configuration that you get from amazon to run your VM.

  1. Small amount of consistent CPU resources and allow you to burst CPU capacity when additional cycles are available. They are well suited for lower throughput applications and web sites that consume significant compute cycles periodically.
  2. Micro Instance 613 MB of memory, up to 2 ECUs (for short periodic bursts), EBS storage only, 32-bit or 64-bit platform.
  3. EC2 Compute Unit (ECU) – One EC2 Compute Unit (ECU) provides the equivalent CPU capacity of a 1.0-1.2 GHz 2007 Opteron or 2007 Xeon processor.
EBS (Amazon Elastic Block Store) – offers persistent storage for Amazon EC2 instances. Amazon EBS volumes provide off-instance storage that persists independently from the life of an instance. Amazon EBS volumes are highly available, highly reliable volumes that can be leveraged as an Amazon EC2 instance’s boot partition or attached to a running Amazon EC2 instance as a standard block device. When used as a boot partition, Amazon EC2 instances can be stopped and subsequently restarted, enabling you to only pay for the storage resources used while maintaining your instance’s state.

Elastic Load Balancing automatically distributes incoming application traffic across multiple Amazon EC2 instances. It enables you to achieve even greater fault tolerance in your applications, seamlessly providing the amount of load balancing capacity needed in response to incoming application traffic.

What’s not free?

Amazon EC2 Monitoring: Amazon CloudWatch enables you to monitor your Amazon EC2 instances, Amazon EBS VolumesElastic Load Balancers, and RDS database instances in real-time.
  • $0.015 per instance-hour (or partial hour)
As an example, a developer may want to monitor 10 Amazon EC2 instances 24×7 for a 30-day period. The Amazon CloudWatch cost would be $108 (or $0.015 per Amazon EC2 instance hour x 10 Amazon EC2 instances x 24 hours per day x 30 days).

Tutorials

Tagged with:  

How super works in ruby

On November 18, 2010, in Technical, by sankalp

Following example shows how super function is interpreted by ruby.

class Rectangle 
	def initialize(side1 , side2) 
		@side1 = side1
		@side2 = side2
	end

	def area
		@side1 * @side2
	end
end

class Square < Rectangle
	def initialize( side) 
		super(side, side)
	end

	def area
		super
	end
end

rect = Rectangle.new( 2, 3 )
square = Square.new(4)
puts rect.area
puts square.area

Output:
6
16

In this example we can see that super calls up the function of the base-class in which it is called.

Tagged with:  

Developer for a startup by IIT graduates

On November 16, 2010, in Careers, by Sanchit Garg

Company name: Golygon
Location: Noida, Delhi, India
Email: sanchitg@gmail.com Phone: 9899 1204 08
URL: www.golygon.com


Description:

This is an opportunity to get involved in an evolving project from scratch and have input into the design and see your work being used by people. You need to be energetic, self-motivated and able to work without constant direction. You need to be trustworthy, have good communication skills (verbal and written) and have a genuine enthusiasm for the web and pride in the quality of your work. Send your resumes to above mentioned email id, if you interested.

Job summary:
• Programmer will work on websites which will require expertise in HTML, CSS, JavaScript(AJAX), PHP, SQL, RubyOnRails
• Integrating websites with Social networks like facebook. It will require expertise in PHP, Java/C++/C  [Optional skills]

Renumeration:
The developer will be given a handsome remuneration per month for his work.

Time Duration:
The duration of work is 6-9 months. [Flexible]

Required skills:
HTML, CSS, Javascript
Frontend development
basic SQL

Desired skills:
Ruby on Rails


Employment Terms: -
Onsite: Yes