DEV Community

Cover image for 8. Database
jicoing
jicoing

Posted on • Edited on

8. Database

After setting up the visitor counter for my website, it was time for setting up the backend database for storing the count data. I chose AWS DynamoDB for this purpose. It is a NoSQL database that works primarily on key value pair, requires only a primary key and doesn’t require a schema to create a table. Sounds magical.

Alt text

DynamoDBAlt Text

I selected create table from the DynamoDB console.

Alt Text

Then I named the table as komlalebuTable and mention the primary key as id with data type as string.

Alt Text

Also I unchecked the default setting of the table and selected on-demand pricing which makes it practically free for my use case.

Alt Text

This table stores the visitor count of my website in near realtime as we can see below using AWS (API Gateway + Lambda) on page load, which we will explore later sections**.

Alt Text

The like button appends the string 'YES' to the count value and adds a record.

Alt Text

The dislike button appends the string 'NO' to the count value and adds a record.

Alt Text

AWS::Serverless::SimpleTable

However this was the manual method of creating a table from AWS console, the final version of the source code is using a table that is created using SAM template (Read more). With the table name as komlalebuTable.

template.yaml

Alt Text

     komlalebuTable:
        Type: AWS::Serverless::SimpleTable
        Properties:
          PrimaryKey:
             Name: id
             Type: String
         TableName: komlalebuTable
Enter fullscreen mode Exit fullscreen mode

And the backend database was setup.

Alt Text

Top comments (0)