How to use AWS DynamoDB as Free Database in Javascript Serverless Webpages

 image

:check_mark:

AWS DynamoDB Demo: Serverless WebPage

DynamoDB Demo hosted on CloudFront

AWS Service

Time Period

Free Tier Limits / Pricing

Amazon DynamoDB Pricing

used as database

Always Free up to 25 RCU/WCU

After 25 units:

$0.00065 per WCU

$0.00013 per RCU

Provisioned Mode: you specify how many RCU/WCU you need

Free 25 RCU and 25 WCU are free - which means 25 read and write requests per second are free forever!

Free 25 GB of data storage for tables

1 RCU = 1 Read / second (4KB)

1 WCU = 1 Write / second (1KB)

Again 1 RCU can do 1 strongly consistent read OR 2 eventually consistent Reads.

AWS CloudFront and AWS S3 explained in our previous post

[optional - used for hosting and CDN]

 

AWS CloudFront and S3 Configuration and Free Pricing

 

Steps to Configure Amazon DynamoDB User Key:

  1. AWS Developer Guide to set up DynamoDB

  2. Go to AWS IAM Console

    1. Click on Users > Add User

    2. Provide UserName and select Access Key option > Next

    3. In Permissions Page > select Attach Policy directly > select DynamoDBFullAccess

    4. Go to next pages and Create User

    5. Download the csv file having Access Key and Secret Key.

 

Steps for SDK and Code:

  1. To run the code from browser Javascript/jQuery, we need AWS SDK

    1. Go to AWS SDK Builder Tool

    2. Clear all other Modules and select only DynamoDB

    3. Select Minified JS file option and Click Build

    4. You should get the JS file like - aws-sdk-2.1253.0.min.js

 

Create DynamoDB Tables Configuration:

  1. Go to DynamoDB in AWS Console for Dynamo DB

  2. Click Create Table

  3. Provide a Table Name

  4. Partition Key - primary / unique column of the table

  5. Sort Key - if Partition Key is not unique then the combination of Partition Key + Sort Key should be unique for each item in the table

  6. Table Class - DynamoDB Standard

  7. For minimum cost -

    1. Item Size <= 1KB

    2. Read and Write per second = 1

    3. Eventually Consistent Read

    4. Standard Write Consistency

    5. Till 25 Read/s and Write/s will be covered by free tier

  8. Select Provisioned Mode with

    1. 1 Read and Write Capacity

    2. Auto Scaling turn off for now - can be set later

  9. Indexes can be created later if required

  10. Encryption - owned by DynamoDB for no cost

  11. Create Table.

 

SDK and JS Code for calls to DynamoDB API:

  1. Amazon Developer Guide for Dynamo DB API Guide

  2. If you are using EC2, you can have your Access Key and Secret in a configuration file in your EC2 instance.

  3. However, we want to save costs $$ and eliminate EC2.

  4. We will use direct browser to DynamoDB calls.

  5. In this tutorial, we will have to keep the Access Keys in our Javascript code (which can later be obfuscated or encrypted for better security)

  6. API Reference - AWS SDK Javascript v2 reference

  7. AWS Example Doc

 

 IAM User Key Config Images:















SDK images:











DynamoDB Table Configuration:













more

styleme



Comments

Popular posts from this blog

Host a Free Static Website with AWS CloudFront and S3