Module 3: Using DynamoDB as a session State Provider

The Amazon DynamoDB Session State Provider allows ASP.NET applications store its sessions inside DynamoDB. This helps applications scale across multiple application servers while maintaining session state across the system.

This project builds an ASP.NET Session State provider that stores session in a DynamoDB table. The session state provider can retrieve from NuGet Packages.

Amazon DynamoDB is a fully managed cloud NoSQL database service – you simply create a database table, set throughput, and let the service handle the rest, and It supports both document and key-value store models. Amazon DynamoDB integrates with AWS Lambda to provide Triggers which enables you to architect applications that automatically react to data changes.

Amazon DynamoDB uses automatic partitioning and SSD technologies to meet your throughput requirements and deliver low latencies at any scale as your data volumes grow and application performance demands increase.

Task lists for module 3: 

  • To create session table in DynamoDB
  • To Install, Manage and  retrieve session state from NuGut Packages
  • To check the session table updating data in the websites

The architecture of the project:

diagram7.png

Steps for the tasks: To create session table in DynamoDB

In this task, I am going to create a pre-create session table in the AWS DynamoDb.

  1. Go to the DynamoDB Database from Services menu in the AWS management console. Click “Create Table” with Hash key attribute name: “SessionId12.jpg
  2. To access your AWS account programmatically, now You need to create Access key and secret key from your Amazon Account. Go to the AWS IAM for creating the Access key under your Security Credentials page. You will get this “Manage Security Credential” from IAM dashboard under “Delete your root access keys”Note: Remember that, you have to download your key during creating access key; Otherwise, you will not able to retrieve your secret access key again.3.jpg4.jpg

Steps for the task: To Install, Manage and  retrieve session state from NuGut Packages

  1. To manage your session state provider, You need to manage your NuGet Packages in your application. Go to your NET702.DinoStore – Manage NuGet Packages via Microsoft visual Studio.
  2. Now You require to the necessary installing references for the NET702.DinoStore project functioning correctly.
  3. In the Microsoft solution explorer, I selected NuGet targets under NuGet packages.7.jpg
  4. Then I go to “Tools, and Click Package Manager Console from NuGet Package Manager. You can also manage package from “Manage Package for Solution” from NuGet Package Manager Tab. I prefer console mode. Note: For your understanding and comfortability I will show two procedures. You can choose anyone.
  5. Package Manager Console Mode:5.jpg
  6. Run the code “Install-Package AWSSDK.DynamoDBv2 and Install-Package AWSSDK.Core, and Install-Package AWSSDK.S3”  for Installing AWSSDK – Amazon DynamoDB 3.3.4.3 and AWS SDK  for.NET, and AWSSDK – Amazon Simple Storage Service 3.3.5.10 ” on the “Package Manager Console” of NuGet with “.NET Framework, Version=v4.5″.6.jpg8.jpg9.jpg10.jpg
  7. Install-Package AWS.SessionProvider” on the “Package Manager Console” to create AWS session provider.11.jpg
  8. Manage Package for Solution Mode: You can also install the “AWSSDK from Manage Packagers for Solution” that I already installed by console mode.12.jpg
  9. Until I’ve been writing, running, and editing my source code from the local server machine, now I will move source code to the cloud. So that I can work on my written code from the cloud platform. I will edit the code in web.config file so that I can create a new session in the cloud using AWS DynamoDB services.

To create the new session, you need to remove previous session details from web.config file ”

“<sessionState

timeout=”20″

mode=”Custom”

customProvider=”DynamoDBSessionStoreProvider”>

type=”Amazon.SessionProvider.DynamoDBSessionStateStore”

AWSAccessKey=”KEY”

AWSSecretKey=”SECRET”

Region=”YOUR AZ”

Application=”DinoStore”

Table=”ASP.NET_SessionState”

ReadCapacityUnits=”3″

WriteCapacityUnits=”1″

CreateIfNotExist=”false”/>

13.jpg

10. Then go to ShoppingCart.cs in NET702.DinoStore.Objects project via Microsoft Visual Studio. I will add a namespace “Serializable” in ShoppingCart.cs. 14.jpg

Serializationis the process of converting the state of an object into a form that can be persisted or transported. It used to save session state in ASP.NET and to copy objects to the clipboard in Windows Forms. It is also used by remoting to pass objects by value from one application domain to another.

Steps for the task: To check the session table updating data in the websites

In this task, I will check the session table on the DynamboDb table and update data on the website. The current situation is that there is no session created under the item in DynamoDB.

  1. Now you need to go back in the AWS DynamoDD to explore the session state table, the current state shows that there are no items.15.jpg
  2. Now you view your application through the browser in order to check it is working properly or now.
  3. Now I will add an item to cart through login in the website by user ID that I have been created previously.When I will add the Dinosaurs into the cart, a session will be created in the DynamoDB table.17.jpg16.jpg

After adding an item to the cart, I explored my DynamoDB item table. I saw a new session has been created on the ASP.NET session state table in AWS.

The Problems can occur and solutions: 

I’ve not got any problems during implementing module-3 but you can come out some issues.

Problem1. If you get difficult to install in AWSSDK 

Solution: If you don’t get “Manager NuGet Package for Solution” from the tool menu NuGet Package Manage. Go to the “Extention and Updates” and then “Online” and download the “AWSToolsAndSDKForNet_sdk-3.3.67.0_ps-3.3.67.0_tk-1.11.6.2′, And install it.18.jpg

You will get “Manager NuGet Package for Solution” under the NuGet Package Manager from Tools.

19.jpg

Problem2: If you forget to download Access Key and You could not able retrieve your secret access key. What will you do?

Solution: Delete the previous Access key from your Security Credentials. Then Create New Access key and download it for the secret key. After that change the new access key and secret key in the source code of the web.config file via Microsoft visual studio.20.jpg

The next Module I will discuss “Configuring the System to Use Simple Queue Service”

Thank you 🙂

Advertisements

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