Pages

Tuesday, February 21, 2012

Get started in "The Cloud" with Amazon Web Services (AWS)

A lot of us have heard about the wonders of "the cloud" and all of the ways that it can benefit us and our businesses, but until you take those steps to see how you could apply it to your situation its hard to really understand what it could do for you. I'm not here to sell any particular cloud service, nor am I preaching that "the cloud" will solve all of your problems and make you a better person. I just wanted to document my personal experience with setting up some web services in the cloud, hopefully it might help someone else who is trying out the cloud for the first time. So, here we go.

I have selected to use Amazon Web Services (AWS) for my cloud service provider. I don't have any personal stake in AWS, I just already have an Amazon account and they have a free tier for a year for new AWS users. Convenient and free, what's not to like?

This post will walk you through setting up a simple server that you could run your web services on. There's a lot not covered in this post, but it will get you started with something concrete that you can use to build on.

Sign up for AWS
The very first thing that we need to do is to sign up for AWS. You'll need to have an Amazon account. Once you have one, you can easily add AWS to it here.

The first thing that we want to do after setting up our AWS account is to configure the "auto-scaling" of our services. We do this to minimize our usage of billable services. In order to change these settings, we'll need the the AWS command-line tools. These tools use the Java run-time, so you will need to have that installed already.

Install the AWS Auto Scaling command-line tools
At the time of this writing, these tools can be downloaded from this page. We just unzip the tools to a directory and remember the name for later. Make sure that the path to the tools doesn't contain any spaces (quoted or not) or things won't work correctly. I created an "AWS" folder in root and then unzipped the tools into that folder.

In order for the tools to work, we need to make sure that we have two environment variables set correctly. The first is "JAVA_HOME" and it needs to be set to the directory where the Java run-time has been installed.
c:\>setx /M JAVA_HOME "C:\Program Files\Java\jre6"

The second environment variable that must be set is AWS_AUTO_SCALING_HOME. It should be set to the path where the command-line tools were unzipped (remember, it cannot contain spaces).
c:\>setx /M AWS_AUTO_SCALING_HOME C:\AWS\AutoScaling-1.0.49.1

Optional: Add the path to the AWS command-line tools to the "PATH" environment variable. This will make running the tools a bit more convenient.
c:\>setx /M PATH "%PATH%;C:\AWS\AutoScaling-1.0.49.1\bin"

Finally, we need to store our credentials so that the command-line tools know which account to operate on. There are a couple of ways to do this, but we're going to stay simple and use our Amazon access keys. To get these keys, first log into your Amazon account and then go to the Security Credentials page. From that page, in the Access Credentials section, you need your Access Key and your Secret Access Key.

Open the key file template (%AWS_AUTO_SCALING_HOME%\credential-file-path.template) and enter your access key and secret access key information in the appropriate sections. Save the file with a new name in the same directory. I saved mine to the common "AWS" folder, as the credentials may be used by other tools as well.

After we've set up our credential file, we need to... set another environment variable! This one tells the command line tools where to find our credential file. Technically, you don't have to use this environment variable, but if you don't then you will have to specify the location of the credential file (or the credentials themselves) with every AWS CLI tool you run.
c:\>setx /M AWS_CREDENTIAL_FILE C:\AWS\aws-credentials.txt

Generate a Key Pair
In order to be able to log into the virtual machines hosting our services, we need a key pair.
1) Open the Amazon EC2 Console
2) From the left navigation bar, click on the "Key Pairs" link
3) Click on the "Create Key Pair" button
4) Give the new Key Pair a name
5) After giving the Key Pair a name, a file with the name "<KeyPairName>.pem" (where <KeyPairName> is the name you gave the Key Pair) will be downloaded. That file contains the private portion of the Key Pair and you will need it to access instances created with the Key Pair. Do not lose this file.

Allow Remote Desktop connections
The default security group does not allow RDP connections from outside IPs. In order to enable RDP connections, you need to add a new rule to the default security group.

1) Open the Amazon EC2 Console
2) From the left navigation bar, click on the "Security Groups" link
3) Select the "default" security group
4) In the bottom pane, select the "Inbound" tab
5) From the "Create a new rule" drop list, select "RDP"
6) Leave the Source field alone
7) Click the "Add Rule" button, observe the new rule added to the TCP section on the right.
8) Click the "Apply Rule Changes".

We've now added a new rule to our default security group that will allow us to remotely connect to the server after we get it running later.

Set up our first EC2 instance
EC2 stands for "Elastic Cloud Computing" and it is the name of the AWS core service that we're going to use to create our web server. EC2 allows you to create virtual machines hosted on the Amazon infrastructure. These virtual machines instances are created from Amazon Machine Images (AMI). These machine images have many different OSes and configurations to choose from, but we're going to keep things simple and just pick a stock Microsoft Windows 2008 R2 with SP1 SQL 2008 R2 Express and IIS. The full list of available AMIs can be found in the AWS Management Console. Before we start a new instance, we need to do a couple of things first.

We need to set up a launch configuration, describing what kind of instance to create and what kind of hardware to run it one. We do that using the as-create-launch-config command:
as-create-launch-config MyLC --image-id ami-e31ccb8a --instance-type t1.micro --key myKeyPair

If everything is set up and working, the tool should respond with "OK-Created launch config".

After we create the launch configuration, we need to actually create the instances of our server. We're going to start very simple and just create a single server instance. We launch the instances of our server with the  as-create-auto-scaling-group command:
as-create-auto-scaling-group MyAutoScalingGroup --launch-configuration MyLC --availability-zones us-east-1a --min-size 1 --max-size 1

The tool should respond with " OK-Created AutoScalingGroup". At this point, you have launched your first EC2 instance, congratulations! The next thing that we'd like to do is to install our web services on our server. To do so, we first need to log into our server for the first time.

Logging into our EC2 instance
To connect to our server instance, we need to retrieve the generated administrator password. To do this, log into the EC2 Console, right click on the instance (if you don't see it, refresh the list) and select "Get Windows Password". You will be presented with a window that requests the private part of the Key Pair for this instance:


Click the "Browse" button and locate the Key Pair file that you created earlier. After you've selected the file, click the "Decrypt Password" button. You will be presented with a new window that shows the decrypted administrator password for that instance. Save that password for later, as you'll need it to log into the instance.

After we have the administrator password, we can just log into our EC2 instance with Remote Desktop. The public name of the EC2 instance is shown on the bottom portion of the EC2 Console:


Getting started with AWS does take a bit of set up, but once you've gone through it once you won't have to do it again. The server that we've set up has SQL Server 2008 Express R2 and IIS installed on it and you don't have to pay a dime to use it since the cost of the OS and other server components are included in the cost of the EC2 instance (which we're getting for free!). You can host a web site on this server, set up web services, or whatever else you can imagine!

4 comments:

  1. How does Server 2008 run on it? I've considered setting one up for webdev, but if it was going to run poorly, I'd just opt for a lighter weight Linux option.

    ReplyDelete
  2. I cannot speak to any concrete performance metrics, but the virtual hardware running the free instances is pretty minimal: 1 ECU (burst to 2 ECUs) and 613MB RAM. I'm sure that you can anticipate how well Windows Server and IIS is going to run on that kind of hardware.

    The free tier hardware is really more for experimenting with the services to see if they would be suitable for your applications. If you decide that you want to use AWS for your hosting or application needs, I'm sure that you'd want to scale up to both better virtual hardware and multiple, load balanced, multi-region servers. The choice of which OS you use in your instances is going to be based on what you plan on deploying to them.

    ReplyDelete
  3. Yeah, when you mentioned hosting MSSQL and IIS on it, I started scratching my head about performance.

    I've been mulling over a reserve EC2 instance, so I'll probably do their trial and upgrade as soon as I see how it scales.

    ReplyDelete
  4. Borgata Hotel Casino & Spa - JTR Hub
    Located in Atlantic City, Borgata Hotel Casino & Spa poormansguidetocasinogambling.com offers the 출장안마 finest in 출장안마 amenities 바카라 and entertainment. wooricasinos.info It also provides a seasonal outdoor swimming

    ReplyDelete