Wednesday, 15 July 2020

Build Your Own Twitter Bot - DynamoDb Table and Repository Class

<< Sending Tweets                                       Table of Contents                                                           Selecting a Tweet >>

In this post, I will create a DynamoDb table and a repository class that allows to read and update items.

DynamoDb Table


Create a new table in AWS DynamoDb called OccultTwitterBotTable
Create a Partition key called TweetId. This will be a unique number that increment for each Tweet item.

The other attributes are:

Message - The text contained within the tweet inclusind hashtags
TweetCount - The number of times the tweet has been tweeted (frequency)
ImageKey - The filename of the image to be attached to the tweet.





TwitterBotService.DAL


Open TwitterBotService.DAL project and add a class called TweetRepository. This will enscapsulate the ability for reading data from our table.



In this class we have the following methods:

GetItem - for fetching a single item giving an identifier.
GetAllItems - Get all items from the table using a scan
UpdateItem - Update attributes for an item
WaitUntilReady - Wait until the table is active

UpdateItem is capable of updating any attribute on an item that is set in the parameter updatedAttributes. After invoking the UpdateItem command, it will call WaitUntilReady() which will stop the code from progressing until the table becomes active again.

<< Sending Tweets                                       Table of Contents                                                           Selecting a Tweet >>


No comments:

Post a Comment