A Newbie’s Guide to Amazon Web Services
Buying online is closely associated with Amazon for a long time we can remember. In addition their recent foray into movie streaming, tablets etc has made them among the leaders in their space. To support the kind of volume in terms of transactions and data they serve through various channels, the backbone of servers has to be world class. They have many data centers and servers to handle the traffic they receive. What they built and worked in-house created a new line of business for Amazon to offer: Amazon web services.
What is Amazon Web Services?
AWS is collection of many services, offered by Amazon, giving developers access to high-end technology resources, without worrying about its maintenance. Initially started with Cloud storage service, S3 which lets you store your data on their servers, back in 2006. After its immense success they added many other services and technologies under AWS umbrella.
Amazon Elastic Cloud Computing
Amazon Elastic Cloud Computing or Amazon EC2 is a web service that offers all the tools required for running applications in the cloud. With its minimalistic web service interface you can set up your instances in matter of minutes, while having complete control over them, unlike the traditional web hosts. The power of EC2 lies with the elasticity part, of course. You don’t need to confine yourself to any thresholds. You can scale-up or scale-down your resources on the fly, as per your requirements. Another best part is that the instances can be launched across the globe, to serve your users better. One thing to note here is that all storage in the instances is transient in nature, i.e. it gets erased when an instance is stopped or terminated. You need to use EBS for persistent storage.
An instance is simply a virtual machine which acts as your own private server. In plain terms, an Instance in AWS world is the same as web server in traditional world; the only difference is that it is managed directly by Amazon. Instances are classified into 13 types, based on their computational power, as with real world specs, in terms of memory, processing speed, core type and storage, at various price points.
While the term instance refers to the hardware specs, it’s utterly worthless without the required software. This is where AMI (Amazon Machine Installer) comes in picture. While instances deal with the hardware side of the game, AMI handles the software part. AMI is a pre-configured operating system and virtual application software bundled together which acts as your web server.
Setting up an Instance
Sign up for Amazon Web Services, you might have to provide your credit card details. But don’t worry, if you are a first timer there, then you should opt for free usage tier!
Step 1: Select a Root Device
Once you’ve setup your AWS account, to get started, just point your browser to the Amazon Console page. From the Dashboard, click the Launch Instance button to open the Instance Wizard. This wizard builds your own server or there are a plenty of Community offerings to choose from. In this case I’ve chosen an Ubuntu installation as it’s easier to install and maintain packages.
Step 2: Configure your Instance
After choosing the root device, configure the instance details like number and type of instances, Availability Zone, Shutdown behavior, etc. You have an option to for Spot Instances also. For the purpose of this tutorial, I’m setting up on a micro-instance.
Step 3: Setup a key pair
For enhanced security, setup a private-public key pair and SSH into your EC2 instance. Download your private key and protect it properly, to prevent any unauthorized access. If you’re working in a team environment, set the key for everyone and share.
Step 4: Configure Firewall rules
You can decide what comes in and what goes out of your application easily with EC2’s Security Groups and take complete control over your traffic.. Basically this works on a simple allow-deny mechanism. You can set up custom Firewall rules for each of your instances or use a pre-defined Security group. Though setting up this is not mandatory, especially during development, in the light of recent attacks on several popular apps, it’s absolutely vital to have a tighter security policy when your app goes live and ideally you should consult with Security experts before setting this up.
Step 5: Call Starbucks
This is the most important step of all, and the best way to good mental health. Okay, I made that up. Anyways, just click the ‘Launch instance’ and help yourself to a hot cup of espresso, while Amazon brings up the instance for you.
Connecting to your Instance
Now, your instance is up and ready. Let’s look at the dashboard for a little detour. It follows the traditional, left side navigation pattern and on the left corner you will find the Region setting. Just click the Instances, left navigation link to grab information about your instances.
Our instances have a lifecycle like computers. You can start them, stop them, reboot them and even terminate at your will. The little green dot on the instance panel indicates that your instance is running. During development phase be sure to stop your instances, to avoid unnecessary billing.
Let’s see how we can connect to your instance. One, you could use a SSH Client from your workspace or else you could use Amazon’s web interface. We’ll see both the approaches.
i) SSH Client
Every server or a website has a unique name and an address- host name and IP address. Similarly your EC2 instance needs an IP address on the web. Amazon allows you to do so with the help of Elastic IP’s. Just click the Elastic IP link on the left hand side to create a new Elastic IP and click the Associate button to attach your instance to this IP. Elastic IP’s are static in nature and doesn’t change unless you manually release them. Copy the public DNS name from the Instances Summary page. We’ll need that later.
You can either use Terminal from your Mac or Putty from your Windows machine. If you’re using Putty, you might have to download Puttygen to convert your .pem private key file to .ppk format, first. Then open Putty -> Connection -> SSH -> Auth and browse for the .ppk file that you just created.
Now go back to the Session tab and paste the public DNS, into the host name field. Connect to setup your connection. During the first time, you’ll get a dialog saying that host key not cached into the registry. Since this is a key we created, go ahead and add it to your registry. Enter ‘ubuntu’ as your username, and Voilà ! That’s how your server looks like:
It’s even simpler on a Mac or Linux based system. Just open your terminal and copy the .pem file you downloaded to the ssh directory and login to your remote machine with the following commands.
sudo cp /source_dir/CloudSpring.pem ~/.ssh/CloudSpring.pem
sudo ssh -i ~/.ssh/CloudSpring.pem your_amazon_public_dns
ii) Web interface
If you don’t have access to a Terminal, you can ssh your instance directly from your browser. But you’ll need to have Java enabled for this to work and it can slow down your system a bit.
Hosting with EC2
Our machine is ready but let’s setup a quick and dirty ruby installation to show up a webpage!
Run to check if ruby exists on this machine:
The most popular rails stack would be Apache + MySQL + Phusion mod_rails.
First let’s install apache and ruby,
sudo apt-get update
sudo apt-get install ruby1.9.1
sudo apt-get install apache2
sudo apt-get install mysql-client libmysqlclient-dev
Now we need ruby gems to handle the rest of the packages.
sudo apt-get install rubygems
Once that is done, you can go ahead with your regular setup as usual.
gem install rails
This will take a while before it completes. Lets set up our first rails project,
rails new helloworld –d mysql
sudo /etc/init.d/apache2 restart
Now, point your browser to the publicdns_address/helloworld, and you should get the Rails welcome page.
And that’s a wrap
Now all that is left is to setup your VirtualHosts to map your DNS. This guide should help you throughout the process. But you promised an easy method? Oh! Yeah, I almost forgot. Bitnami offers the complete stack, of any for free. Just sign up for their service, give your AWS credentials, and set up the stack.
Amazon AWS is an awesome service that has a lot of tricks under its sleeve. Obviously there is a great deal to cover, and we’ll try to rectify this in the future articles. What would you like us to cover here in the future? Feel free to join us in the discussion and let us know about your thoughts. Thanks for reading, and stay tuned.