Petboard: An ASP.NET Sample Using Amazon S3 and Amazon SimpleDB

Articles & Tutorials>Petboard: An ASP.NET Sample Using Amazon S3 and Amazon SimpleDB
The Petboard sample application shows how to use Amazon Web Services in an ASP.NET application. The web application is a catalog of pets and information about each pet, including a profile photo, likes, and dislikes. Petboard shows how to organize structured data using Amazon SimpleDB, serve images from Amazon Simple Storage Service (Amazon S3), and implement ASP.NET Membership using Amazon SimpleDB.

Details

Submitted By: Craig@AWS
AWS Products Used: Amazon S3, Amazon SimpleDB
Language(s): C#
Created On: March 5, 2010 3:55 PM GMT
Last Updated: September 26, 2013 12:24 AM GMT
By Juan J. Perez, ekeepo, LLC and Tyler Schlegel, HotMethod, LLC

Introduction to the Petboard ASP.NET Sample

The Petboard ASP.NET sample application recently added to the AWS SDK for .NET implements an ASP.NET application using Amazon Web Services as the only backend. The challenge of running a web application is the need for a scalable and highly-available backend system that can serve a large number of clients. Often the HTML served by the web server is a small percentage of the total bandwidth served. By using AWS to store data and images, Petboard can scale to a very large user base.

The Petboard application implements the following capabilities:

  • ASP.NET Membership based on Amazon SimpleDB
  • Storing pet data in Amazon SimpleDB
  • Storing pet images in Amazon S3
  • Uploading pet images to Amazon S3 from an ASP.NET application

Upon running the application, Petboard creates a sample data set of sample pets which is uploaded to your AWS account. The image below shows the running Petboard web application, populated by some pets owned by the Amazon Web Services team.


Figure 1

Signing Up for Amazon Web Services

The Petboard ASP.NET sample requires an AWS account to use Amazon Simple Storage Service (S3) and Amazon SimpleDB.

Signing Up for a Service

  1. Go to the home page for Amazon Simple Storage Service (Amazon S3) and Amazon SimpleDB.
  2. Click the Sign Up button on the top right corner of the page. If you don't already have an AWS account, you are prompted to create one as part of the sign up process.
  3. Follow the on-screen instructions.

AWS sends you a confirmation e-mail after the sign-up process is complete. At any time, you can view your current account activity and manage your account by going to http://aws.amazon.com and clicking Your Account.

Getting Your AWS Security Credentials

In order to use the AWS SDK for .NET, you will need your AWS security credentials, which AWS assigned you when you created your AWS account. Security credentials are used to authenticate requests to an AWS service and identify you as the sender of the request. The security credentials used with the AWS SDK for .NET are a pair of public/private keys:

  • Access Key ID
  • Secret Access Key

IMPORTANT: Your Secret Access Key is a secret, which only you and AWS should know. It is important to keep it confidential to protect your account. Store it securely in a safe place. Never include it in your requests to AWS, and never e-mail it to anyone. Do not share it outside your organization, even if an inquiry appears to come from AWS or Amazon.com. No one who legitimately represents Amazon will ever ask you for your Secret Access Key.

Downloading the Petboard ASP.NET Application

The Petboard ASP.NET AWS SDK sample application is packaged in AWS SDK for .NET, which can be downloaded from the following location:

http://aws.amazon.com/sdkfornet

Introduction to the AWS SDK for .NET

The AWS SDK for .NET is an all-in-one .NET library that abstracts much of the low-level plumbing associated with programming for the AWS cloud, including authentication, request retries, and error handling. The AWS SDK for .NET enable .NET developers to build .NET applications using the AWS Cloud infrastructure services including Amazon Elastic Compute Cloud (Amazon EC2), Amazon Simple Storage Service (Amazon S3), Amazon Simple Queue Service (Amazon SQS), and Amazon SimpleDB.

The following screen capture (Figure 2) shows the .NET tool 'ildasm.exe' viewing the AWSSDK.DLL assembly. The screen capture shows a number of the services supported by the SDK.

  • Amazon Elastic Compute Cloud (Amazon EC2)
  • Amazon Simple Storage Service (Amazon S3)
  • Amazon Simple Queue Service (Amazon SQS)
  • Amazon Elastic Map Reduce
  • Amazon SimpleDB
  • Amazon Elastic Load Balancing
  • Amazon CloudWatch
  • Amazon CloudFront
  • Amazon Auto Scaling


Figure 2

In the Petboard ASP.NET sample application, we're using the AWS SDK for .NET to create an ASP.NET application which uses the AWS services to store data for our pet application. The AWS .NET SDK makes it very simple to create a .NET application.

In the Petboard application, we're using only the following AWS SDK for .NET types:

  • Amazon.S3
  • Amazon.S3.Model
  • Amazon.SimpleDB
  • Amazon.SimpleDB.Model

Downloading the AWS SDK for .NET

In order to use the Petboard ASP.NET Application, you'll need to visit http://aws.amazon.com/sdkfornet/ and download the AWS SDK for .NET. You can also read and view the video at the 'Getting Started with the AWS SDK for .NET' guide at http://developer.amazonwebservices.com/connect/entry.jspa?externalID=3051. The .NET Development forum http://developer.amazonwebservices.com/connect/forum.jspa?forumID=61 is a great community based resource to get questions answered and learn about how others in the community are using the AWS SDK for .NET.

Running the Application

Before we dive into the AWS.NET SDK and dissect the application, let's run it to see it working.

To run the application

  1. Download and install the AWS SDK for .NET. For more information, see http://aws.amazon.com/sdkfornet.
  2. After installing the SDK, go to %INSTALL_DIRECTORY%\AWS SDK for .NET\samples\Petboard.
  3. Open the PetBoard.sln file in Visual Studio.
  4. Set your AWS credentials in the Web.config file. In Solution Explorer, double-click on Web.config to display it in the Visual Studio editor. Scroll to the <appSettings> element and enter your AWS Access Key and AWS Secret Key for the value attributes of the <add> sub-elements of <appSettings>.
    <appSettings>
        <!-- AWS CREDENTIALS -->
        <!-- Uncomment the section below and add your credentials if you are not using a deployment mechanism that manages credentials. -->
        <!--
        <add key="AWSAccessKey" value=""/>
        <add key="AWSSecretKey" value=""/>
        -->
    </appSettings>
    
  5. Save and close Web.config.
  6. Press F5 to start the application.
  7. When running the application for the first time, Petboard will guide you through the process of configuring the application:
    • Create an account. This will create an account inside the 'petboard-membership' Amazon SimpleDB Domain inside your AWS account.
    • Populating sample pet data. Upon running the Petboard application, the code will upload data into your Amazon SimpleDB and Amazon S3 accounts. The data stored in Amazon SimpleDB will not cross the free tier, but you will be charged for the images uploaded to Amazon S3.

Dissecting the Petboard project

The Petboard application is an ASP.NET application that has a number of ASP.NET pages and has a master page named Site.Master.


Figure 4

Default.aspx is the primary page where the user is first directed when the application is loaded in a browser. As shown in Figure 4 below, each of these pages has a corresponding class which both presents a user interface to the user and interacts with the AWS SDK for .NET library.

The concept of public and private pet profiles is implemented by using a shared Amazon SimpleDB domain ("petboard-public"). Each user has a corresponding private pet domain ("petboard-<user name>") and clicking the "public" check box in the pet profile pushes a copy of that single pet into the public domain. Un-checking the public checkbox deletes it from the public domain.

As shown in Figure 5, the PetDetails.aspx.cs code file uses the AmazonS3Client and AmazonSimpleDBClient classes to get data from Amazon SimpleDB and Amazon S3.


Figure 5

Clearing the Default Pets

In order to start from a clean state you need to clear your Amazon S3 and Amazon SimpleDB accounts of the data created by the Petboard application. Clean the data from your account through the following steps:

  • Cleaning Amazon SimpleDB: Use your favorite Amazon SimpleDB browser and delete the Amazon SimpleDB domains which start with the naming format 'petboard-*'. We used the Mindscape SimpleDB Management Tools which provide a view of the Amazon SimpleDB data from within Visual Studio. You could also use the AWS Toolkit for Visual Studio.
  • Cleaning Amazon S3: Use your favorite Amazon S3 browser to navigate to the root of your Amazon S3 account. You will see a number of buckets with the following name formats 'petboard-*'. Delete all the buckets which are named based on this format.

What Next?

In order to provide some further hands on experiences with the AWS SDK for .NET, there are a few features you can add:

  • Deploying the Petboard ASP.NET application to EC2: Although you can run and test the application on the local testing web server provided by Microsoft Visual Studio 2008, the real test is to deploy the application to a Windows Server Amazon EC2 instance. This will allow you to share information with other people on the internet. with the AWS Toolkit for Visual Studio, you can easily deploy the Petboard application to either AWS Elastic Beanstalk or AWS CloudFormation.
  • Use Amazon Simple Queue Service (SQS) to create thumbnails. The Petboard application does not manipulate the size or format of the pet images when they're uploaded. Since we don't want to block the user when the user uploads an image of a pet, we'll create a PetBoard Image Processor which will create thumbnails of the pet images. As shown in the UML Sequence Diagram in Figure 10 below, we'll use Amazon SQS as the means of communication between the PetBoard ASP.NET Application and the PetBoard Image Processor which will use Amazon SimpleDB and Amazon S3 as a means for structured data storage and image storage, respectively.


Figure 6

©2014, Amazon Web Services, Inc. or its affiliates. All rights reserved.