Lab 3. Using DynamoDB as a Session State Provider

Overview

In this lab we will create a session table with the help of DynamoDB service, we will use the NuGet packages to communicate with asp.net.

DynamoDB

Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale. It is a fully managed cloud database and supports both document and key-value store models.Amazon DynamoDB Accelerator (DAX) is a fully managed, highly available, in-memory cache that can reduce Amazon DynamoDB response times from milliseconds to microseconds, even at millions of requests per second.

Nuget Packages in Visual Studio

NuGet is the package manager for the Microsoft development platform including .NET. The NuGet client tools provide the ability to produce and consume packages.

By doing this lab you will learn:

  • How to create a session table in DynamoDB
  • How to install Nuget packages, manage and how to use it for retrieving data
  • Checking the session table getting updated when a order is placed

The image shown below is the architecture for this lab.

s

To start with this lab you should 1st create a session table. To create a session table click on > Services >and choose DynamoDB.

1

When you are on the DynamoDB click on Create table.

2

Give the table name as ASP.NET_SessionState
Give the Primary key  as Hash 
Hash Attribute name as SessionId
Click on Add Index and Click on Create

3

When the SessionState table is created, click on the radio button next to ASP.NET_SessionState and on the right hand side you can see the details tabs with different features.

To give the Read Capacity=3 and Write capacity=1 click on capacity tab and you can change.

6

To turn off the alarms click on the Alarms tab and select the alarms and click on Delete.

7

To create an Access Key click on your profile name and select My Security Credentials. When you are on your security credentials page click on Create New Access Key.

Capture

A pop-up window will appear and click on download to download your key file.

1918

When you have finished downloading the key go to your visual studio and go to your project. You have to download ‘AWS SDK’ for .NET to install that click on Project> Manage NuGet packages.

Note: If you have ‘AWS SDK’ Package no need to install it again. When an error occurs try to install a degraded version of it, do not update it to the latest version.

9

1011

When you have installed it click on your Web.config and remove the line ‘ and replace the code with the following code which is shown below.

1314

When the code is properly edited, Select NET.702.Dinostore.Object and select the file shoppingCart.cs replace the code as given below.

[Serializable]
public class ShoppingCart
{
public string CustomerId { get; set; }
public DateTime DateCreated { get; set; }
public string CcType { get; set; }
public string CcNumber { get; set; }
public string CcExpiration { get; set; }
public List Items { get; set; }

public ShoppingCart()
{
DateCreated = DateTime.Now;
Items = new List();
}

}
[Serializable]

k

12

When you are done doing necessary changes to the codes go back to your AWS dynamoDB console and explore the sessiontstate table you should see no items.

14

Browse your application from the browser and login with the credentials. Add a Dinosaur to the cart.

15

Click on check out.

16

Go back to your AWS dynamoDB console and explore the sessionstate table. and you will see an item.

17

When all these steps are completed successfully you are done with lab 3.

Conclusion

By the end of this lab you have learned:

  • How to create a session table in DynamoDB
  • How to install Nuget packages, manage and how to use it for retrieving data
  • Checking the session table getting updated when a order is placed

Budget Plan

DynamoDB is a part of AWS’s Free tier. Pay only for what you use.  There will be no minimum fee. AWS customers can get started with Amazon DynamoDB for free. The customers will get 25GB as for free storage and up to 25 write capacity units of ongoing throughput capacity and 2.5 million read requests from DynamoDB Streams for free. When you go beyond your free tier they will start charging and price varies according to the regions as for me i have created my DynamoDB service in US West (Oregon) it if i go beyond my free tier it will cost me for throughput:

  • Write Throughput: $0.0065 per hour for every 10 units of Write Capacity (enough capacity to do up to 36,000 writes per hour).
  • Read Throughput: $0.0065 per hour for every 50 units of Read Capacity (enough capacity to do up to 180,000 strongly consistent reads, or 360,000 eventually consistent reads, per hour).

As for the data storage if i go over 25GB it will cost $0.25 per GB-month. To Save up your budget you should make sure that you create the services in the Same Region.

 

Advertisements
This entry was posted in Dinostore Labs. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s