

Amazon Web Services(AWS) EC2
EC2 stands for Elastic Compute Cloud, it is a web service by Amazon Web Services that provides resizable compute capacity in the cloud. It is designed to make web-scale computing easier for developers. In this blogpost, I am going to show how to set up RStudio server on an EC2 instance, which will allow you to access RStudio from your system using SSH Client or your web browser. For this purpose I am using AWS free tier, which includes 750 hours of Linux and Windows t2.micro instances each month for one year (Note:-To stay within the Free Tier, use only EC2 Micro instances)
Setting up RStudio Server on an EC2 instance:
Step 1 : Go to http://aws.amazon.com/ec2/, sign up for it. You will require a credit card with a minimum balance of $1 for this, don’t worry if you don’t have one, visit https://www.entropay.com/ create a virtual credit card and use it for creating the account.
Step 2 : Open AWS Management Console from My Account/Console Tab and select EC2
Step 3 : Click on Launch Instance to create a new EC2 instance.

Step 4: It will open a wizard where we need to configure the instance. Select the Community AMIs tab, check the Ubuntu check box and select any 64-bit AMI. 
Step 5 : Now select any Free tier micro instance to use and click on Next

Step 6 : For the next two steps of this wizard leave the settings as they are originally i.e for Configure Instance and Add Storage leave the settings at default.
Step 7 : Now we need to create a new security group. A security group is a set of firewall rules that control the traffic for your instance. In this step, you can add rules to allow specific traffic to reach your instance. For example, if you want to set up a web server and allow Internet traffic to reach your instance, add rules that allow unrestricted access to the HTTP and HTTPS ports. Add the rules shown in the image below to your instance(Note:The last rule in this list i.e. port 8787 is used to access RStudio server). Now Click on Review and Launch.

Step 8 : Review your settings and click on the Launch button, it will prompt you to download the key pair which you will need to access your instance. Then click on Launch Instances


Step 9 : On the next page you can see your Instance loading, the Instance will change from Pending to Running, once it is active.
Step 10 : Now your instance is running and you require a SSH Client to access the same. Download PuTTY (a SSH Client) from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html and install it on your system.(Note: You can access your instance by your browser also, click on Connect to do the same)
Step 11 : After installing, open PuTTY gen on your system. Click on Load and Open the key pair that you have downloaded in Step 8. Then click on Save Private Key and save the generated key.

Step 12 : Now open PuTTY, go to the Session tab and in the Host Name field type ubuntu@YourPublicDNS. You can find your public DNS from EC2 dashboard.

Step 13: Now in PuTTY, go to Connection–> SSH –> Auth. Click on Browse and select the private key you have created from PuTTY gen in step 11. Finally click Open.

Step 14 : After completing the previous step a new window will open like the image below.

Now to install RStudio Server on this instance type the following command in this window one by one:
#Install latest version of R
sudo apt-get install r-base
#Install in order to use RCurl & XML, useful if you want to use R to connect to any web data/APIs.
sudo aptitude install libcurl4-openssl-dev
sudo apt-get install libxml2-dev
#Install a few background files
sudo apt-get install gdebi-core
sudo apt-get install libapparmor1
#Download and Install RStudio Server
wget http://download2.rstudio.org/rstudio-server-0.97.336-amd64.deb
sudo gdebi rstudio-server-0.97.336-amd64.deb
Step 15 : Now to open RStudio server, go to your web browser and navigate to the Public DNS of your image on port 8787, similar to:
http://ec2-XX-XX-XX-XXX.compute-1.amazonaws.com:8787














