Getting Started with Amazon AWS and Elastic Beanstalk

We wondered how easy it would be for the average developer to use one of the cloud services to put up one of the very simplest of ASP.NET MVC applicastions, NerdDinner, complete with database. We asked Bud, who turned into an intrepid explorer of the Amazon to show us the way.

1525-image001.jpg

I wonder if we’d have done better with taller waders

The other day I watched The Great Escape. In one segment they brew up a batch of potato moonshine. I was reminded of the husky, breathy “Wow” in the taste testing scene when I visited Amazon’s Amazon Web Services offering. It’s like jumping in to a stream with hip waders and discovering that you need taller waders.

Amazon has so many services that I’m going to just skim the surface here. It would take a few weeks to cover everything Amazon offers. This article will be about Amazon RDS which in itself offers flavors for MS SQL Server, Oracle and MySQL. You can even use MS SQL Express! In this article, my objective was simply to deploy, into Amazon Web Services, a version of the sample ASP.NET MVC application, NerdDinner in order to discover how easy it would be. I will also cover the use of Amazon’s Elastic Beanstalk

There is a video offering on Amazon’s web services site covering putting a version of Nerd Dinner up on AWS. It feels like a good idea to step through that process in a written out tutorial fashion.

http://www.youtube.com/watch?v=z-N0z5K_WFI&feature=youtu.be

First a caution

1525-image002.jpg

Intrepid explorers to the Amazon
 have to start somewhere

Every cloud offering I’ve found requires you to establish an account. That account must be backed by a payment method and it is possible to inadvertently incur charges. It was explained to me like renting a hotel room. Whether you stay in the room or sleep elsewhere the room is still charged to you. On the good side, most services provide a means for developers and first time uses to test things. With Amazon it’s called a “Free Usage Tier”, which is available to all new users and some existing users. So read the fine print if you want to avoid incurring charges for ANY of the cloud offerings.

Getting started

I’m not going to walk you through the sign up process. The screens are self-explanatory. The payment method that you choose will be charged a dollar for each service you sign up for, but the dollar will be refunded. It’s Amazon’s method of assuring you are who you say you are. Also, if you have an existing Amazon account then you can use that account.

I lied.

Sorta – I wrote the introductory part of this article before I did much exploring in the AWS world. What I’ve found is like silent but deadly. I can’t believe how a service of this magnitude has remained off my radar for this long. It is – to be absolutely true – part of the perception of Amazon as an online bookstore. It turns out they may well be bigger than any other cloud offering. My first impression was that they had a single data center. As it turns out they have (at the time of writing) 7.

  1. US East (Northern Virginia)
  2. US West (Oregon)
  3. US West (Northern California)
  4. EU (Ireland)
  5. Asia Pacific (Singapore)
  6. Asia Pacific (Tokyo)
  7. South America (Sao Paulo)

You can draw your own conclusions about the distribution of these centers, but it seems that they do a very good job of covering the major population areas correctly.

Services offered

My first impression was – ah, AWS has 19 products or services they offer but then I started digging. Here’s a more or less simplified list:

  1. Compute
    • Amazon Elastic Compute Cloud (EC2) the basic compute capacity.
    • Amazon Elastic MapReduce to process “vast amounts of data.”
    • Auto Scaling
    • Elastic Load Balancing
  2. Content Delivery
    • Amazon CloudFront allows distribution of content globally with low latency.
  3. Database
    • Amazon Relational Database Service (RDS) MySQL, Oracle and MS SQL Server including Express
    • Amazon DynamoDB fully-managed NoSQL database service (blob?)
    • Amazon SimpleDB managed NoSQL database (tables?)
    • Amazon ElasticCache in-memory cache in the cloud (queues?)
  4. Deployment & Management
    • AWS Identity and Access Management (IAM)
    • Amazon CloudWatch provides monitoring for cloud services
    • AWS Elastic Beanstalk to deploy and manage cloud applications
    • AWS CloudFormation to create and manage a collection of resources
  5. Application Services
    • Amazon CloudSearch
    • Amazon Simple Workflow Service (SWF)
    • Amazon Simple Queue Service (SQS)
    • Amazon Simple Mail Service (SES)
  6. Networking
    • Amazon Route 53 whoa – DNS management!
    • Amazon Virtual Private Cloud (VPC) yup
    • AWS Direct Connect to establish a direct connection from your premises to the cloud.
  7. Payment & Billing
    • Amazon Flexible Payment Service (FPS) you’ll know if you’ve ever used Amazon OneClick
    • Amazon DevPay hum – a way for developers to collect for their AWS offerings?
  8. Storage
    • Amazon Simple Storage Service (S3)
    • Amazon Elastic Block Storage (EBS)
    • AWS Import/ExportAWS Storage Gateway
  9. Support
    • AWS Premium Support
  10. Web traffic
    • Alexa Web Information Service
    • Alexa Top Sites
  11. Workforce
    • Amazon Mechanical Turk (temp workers!!!)

That’s about 30 services under the Amazon Web Services banner and many have additional entries. Actually, looking at some web content, one person says “82 (services) in 2011 alone”.

Signing up

Here’s the screen you get when you first visit AWS Web Services.

1525-image003small.png

Once you’ve signed up and received your verification emails, the next step is to download the appropriate SDK for your development purposes. I chose to download the SDK for.NET for this article.

1525-image004small.png

Once you have the SDK simply install it. One of the results will be new projects available in Visual Studio 2010. The templates are for C# only as far as I can tell.

Let’s play around

The whole AWS thing is so involved it’s scary. I’ve been messing with it for a few days now just to get a feel. I’ve signed up for my account and done all of the necessaries to get to the web page illustrated here.

1525-image005small.png

Besides the Home tab, you should see 19 additional tabs representing the services available. Left click the ‘Elastic Beanstalk tab to get the following screen.

1525-image006small.png

I’ve preselected the 64bit Windows Server 2008 R2 running IIS 7.5 because I’m familiar with it. I suspect that the results here make little difference. I’ve also left Launch a sample application checked because I really just want to see what’s going to happen. So click the Launch Application button to get the following screen.

1525-image007small.png

I had done this once so some of the messages apply to a previously terminated app. You can click the arrow to the left of the Environment Details to follow the progress. Spinning up the application will take a few minutes so be patient.

1525-image008.png

Click the URL to launch the application and you should see this.

1525-image009small.png

In the third item under ‘What’s Next?‘, I’m going to walk through the NerdDinner application. I’m not sure at this point what added value I’ll provide but maybe it will force you to jump in the water. By now your hip waders should be tall enough.

CAUTION
Before you start be sure Elastic Beanstalk is supported in the zone you select. As of this writing I know that the US East (Virginia) zone is available. If you choose a zone that doesn’t support the Elastic Beanstalk you won’t get it as a deployment option later.

Building and deploying the Nerd Dinner application

I used the steps in the following Amazon documentation and found myself struggling in a few places. The instructions are fairly clear but in some instances they seem to gloss over some steps that are not as intuitive as they might be.

http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_deploy_NET.html

Getting the source code

You can download the Nerd Dinner source from here:

http://nerddinner.codeplex.com/

It’s a zip file. I extracted it to my Visual Studio 2010 “my documents” under Projects. Once you’ve extracted it, open Visual Studio 2010 and open the project solution file. My suggestion is that you should use this link for your basic instructions.

I will try to cover all of the steps, but it’s nice to have two outlooks.

To script the NerdDinner database

  1. In Server Explorer, right-click ‘Data Connections’, and then click ‘Add Connection’. 1525-image010.png
  2. In the ‘Add Connection’ dialog box, click ‘Change, and then click ‘Microsoft SQL Server Database File’. Click OK‘.1525-image011.png
  3. Click ‘Browse’that is next to the ‘Database file name’ box, and select the NerdDinner.mdf file located in the NerdDinner/App_Data directory. Click ‘Open.1525-image012.png
  4. In Server Explorer, right-click NerdDinner.mdf, and click ‘Publish to provider’.

    Note that the database you just selected is pre-selected.1525-image013.png

  5. In the Database Publishing wizard, click ‘Next’ twice. On the ‘Select an Output Location’ page, note the path and file name in the ‘File name’ box. You will need this for later.
  6. Click ‘Finish’ twice to so as to accept all defaults in the wizard.1525-image014.png

I know – all of this to set up a SQL database script. This can be more easily accomplished using Red Gate SQL Packager. SQL Packager has to be one of the niftiest creations on the planet!

Launching an AWS RDS database

In the AWS Explorer, expand the Amazon RDS entry and right-click ‘DB Instances’.

1525-image015.png

…then select ‘Launch DB Instance’. If you want to stay in the Free Tier, then select the Microsoft SQL Server Express Edition. The entries look similar, so choose correctly.

1525-image016.png

In the following dialog, a Micro instance is probably going to be all you’ll need for testing.

I’ve used mostly the same values as Amazon’s walkthrough. I used awsuser as the Master User Name and my password as the password.

1525-image017.png

Selecting defaults in most of the following dialogs is okay. Clicking Launch will start building the db and this will take some time. Double click demodband you will see the status registering a yellow dot followed with “creating.” Be patient – this really does take minutes.

1525-image018.png

Once it’s ready then you should see a Status of “Available”. And in case no one picked it up I blew it and built this on US West (Oregon) instead of US East so I had to do it over.

1525-image019.png

Once finished, the right-click the db instance and select ‘Create SQL Server database’.

In this dialog the system tries to determine your CIRD/IP.

1525-image020.png

Once the connection is established you can move on to creating your db.

1525-image021.png

Clicking OK will build the requested database.

Updating the Nerd Dinner connection string

In the Server Explorer select the rds.demodb.mydb entry.

1525-image022.png

In the Properties window copy the Connection String.

1525-image023.png

Now I found this a little counter-intuitive. You need to copy the connection string to the highlighted area here. And Holy Batman it gets worse. I spent a few days and AWS tech support came to the rescue. I left out an &quot – so here’s how the entire line should look.

With your password substituting for the *******. I truly hate connection strings!

 

1525-image024small.png

 

This is the NerdDinnerEntities string and I’ve turned it in to 3 lines so you can see where to paste the connection string you just copied. You can just scroll to the end of the string to do the paste. Finally save the modified file. I’m not really sure that this works but it doesn’t error out.

1525-image025.jpg

I suspect that this is due to a connection string problem, but it isn’t how I imagined the Amazon

Load NERDDINNER.MDF.sql

Load NERDDINNER.MDF.sql that you saved earlier into Visual Studio and click the Connect icon on the toolbar.

1525-image026.png

In the AWS Explorer double-click the demodb and make a copy of the endpoint.

1525-image027.png

In the ‘associate Properties window, copy the Endpoint.

1525-image028.png

In the connection dialog, paste the endpoint into the Server name box and also fill in the other entries appropriately.

1525-image029.png

Once you are connected, you select the appropriate database and click the execute button. If the script succeeds then you should see Command(s) completed successfully in the bottom window.

1525-image030.png

Now close the Nerddinner.MDF in Server Explorer.

A little sidetrack

Among many other things, I have SQL Server 2012 installed. When using the instructions provided by Amazon, I ended up with my Visual Studio 2010 using SQL Management Studio 2012; I think it may have not done things right. To remedy that problem I used SQL Server Management Studio 2008 R2. I connected to my AWS database using the endpoint and ran the NERDDINNER.MDF.sql script against the mydb database by copying it to a new script instance and executing it.

Deploying Nerd Dinner using the Elastic Beanstalk

First, a deep bow to all of you who have gotten this far. It’s not that AWS is difficult but it is so rich it requires a considerable amount of perseverance. Let’s finish this up so that you can deploy your first real application to the Elastic Beanstalk. I will not be expecting the Nerd Dinner site to work – I just want to see a ‘Status: Environment is healthy. So firstly, right-click the NerdDinner item in the Solution Explorer to get this context menu, and then click ‘Publish to AWS.

1525-image031.png

The result should be the following dialog box. Note again that this is being done on the East US zone and thus includes the Elastic Beanstalk.

1525-image032.png

Click the AWS Elastic Beanstalk entry to get the following.

1525-image033.png

You can leave the defaults and click Next.

1525-image034.png

Enter a name and an Environment URL. I’ve used matching entries though I’m not sure whether that’s required. Be sure to click the ‘Check availability… button to see if the URL is available, and then click ‘Next.

1525-image035.png

Here, simply check the box for your Database and click ‘Next.

1525-image036.png

Once here, you can look over your selections and then click ‘Deploy’. You will see the following as the Elastic Beanstalk begins the deployment operation. Notice the Status entry of Launching.

1525-image037small.png

Once complete, you should see the following screen.

1525-image038small.png

Again wait for the ‘Status: Environment is healthy‘, at which point you can click the URL to launch the Nerd Dinner site on Amazon Web Services.

What a hoot!

I had concluded that my deployment was a failure but on further reading and inspection we have NOT implemented the registration and logon part or the app. So when you try to logon you get this screen.

1525-image039small.png

Notice the recommendation to use a third party account. Since I have a Google account I chose to logon using that. You can also run the application locally going against the AWS database, so there are lots of options. It’s not all duck soup but AWS has many options available for running your applications

1525-image040small.png

Fill in the details for your dinner and save it.

Now proceed on over the SQL Server Management Studio (You can also use Visual Studio) and see that your data has been saved on the AWS database (click through for full details).

1525-image041small.png

When I first tried to run the Nerd Dinner site it displayed correctly which was, after all, the whole point of this exercise but it didn’t WORK quite as it was supposed to. I had, at this stage, successfully deployed a site to the AWS Elastic Beanstalk and learned a whole lot along the way.

It took a few days and very frustrating days at that but I did finally get Nerd Dinners deployed and working. It turns out (and I’ve corrected this in the connection string information supplied earlier) that I’d left out a &quot. Once I corrected the connection string everything fell into place. It was like slogging through sludge, but I hope it helps others.

Oh and by this time you should have hip waders like those used by the guys in the cranberry bog commercials!