How to use AWS DynamoDB as Free Database in Javascript Serverless Webpages
image
AWS DynamoDB Demo: Serverless WebPage
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] |
|
Steps to Configure Amazon DynamoDB User Key:
AWS Developer Guide to set up DynamoDB
Go to AWS IAM Console
Click on Users > Add User
Provide UserName and select Access Key option > Next
In Permissions Page > select Attach Policy directly > select DynamoDBFullAccess
Go to next pages and Create User
Download the csv file having Access Key and Secret Key.
Steps for SDK and Code:
To run the code from browser Javascript/jQuery, we need AWS SDK
Go to AWS SDK Builder Tool
Clear all other Modules and select only DynamoDB
Select Minified JS file option and Click Build
You should get the JS file like - aws-sdk-2.1253.0.min.js
Create DynamoDB Tables Configuration:
Go to DynamoDB in AWS Console for Dynamo DB
Click Create Table
Provide a Table Name
Partition Key - primary / unique column of the table
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
Table Class - DynamoDB Standard
For minimum cost -
Item Size <= 1KB
Read and Write per second = 1
Eventually Consistent Read
Standard Write Consistency
Till 25 Read/s and Write/s will be covered by free tier
Select Provisioned Mode with
1 Read and Write Capacity
Auto Scaling turn off for now - can be set later
Indexes can be created later if required
Encryption - owned by DynamoDB for no cost
Create Table.
SDK and JS Code for calls to DynamoDB API:
Amazon Developer Guide for Dynamo DB API Guide
If you are using EC2, you can have your Access Key and Secret in a configuration file in your EC2 instance.
However, we want to save costs $$ and eliminate EC2.
We will use direct browser to DynamoDB calls.
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)
API Reference - AWS SDK Javascript v2 reference
IAM User Key Config Images:










Comments
Post a Comment