What is DynamoDB

DynamoDB is AWS NoSQL DB Service. The term “service” here means that Amazon takes care of the hardware, patching, and scaling. NoSQL Database is good for fast storage, which can easily scale horizontally. Also, it’s good in the case that your data doesn’t have a fixed set of fields. When each record seems like a document (that’s why Microsoft named his NoSQL DB DocumentDB). Billing for DynamoDB depends on few factors, such as read and write capacities.

Why C#?

In my previous article, I wrote about it. Here I can add that Amazon has a very good Data Model and Object persistent interface, which allows working with records as with usual POCO objects.

Initialize client

For work with DynamoDB, we need to use AWSSDK.DynamoDBv2 NuGet package and using it along with **Amazon.DynamoDBv2.DataModel. **Init client and context as shown below.

Create table

To create a table we need to decide which mandatory fields it should have and which keys.

Define table parameters

  • **Partition key **— unique key for every record, there isn’t allowed 2 records in one table with the same partition key.
  • Sort key — second unique key for the key combination. You will be able to query the table by the combination Partition key + Sort key.
  • **Local Secondary index **— another pair for searching. The partition key should be the same as the Partition key, but the Sort key will be different. LSI should be created with the table.
  • Global Secondary index — In case that table is already created you can create GSI. GSI is creating a “projection” of the table, in fact, another table for search.

#lambda-function #c# #lambda

Working with AWS DynamoDB using Lambda and C#
1.20 GEEK