Amazon DynamoDB For The .NET Developer
This blog post is a collection of other posts that covers various aspects of Amazon DynamoDB and other services you can integrate with when building serverless applications.
Table of Contents
This article is sponsored by AWS and is part of my AWS Series.
DynamoDB is a cloud-hosted NoSQL database provided by Amazon Web Services (AWS). DynamoDB provides reliable performance, a managed experience, and a convenient API access to interact with it.
This blog post is a collection of other posts that covers various aspects of Amazon DynamoDB and other services you can integrate with when building serverless applications.
Getting Started With Amazon DynamoDB
If you are completely new to AWS DynamoDB and just getting started, check out my getting started article below.
It covers an introduction to DynamoDB, an understanding of how to create tables, and doing basic Create Read, Update, and Delete (CRUD) operations from the .NET application using the DynamoDB SDK.
Running DynamoDB on Your Dev Machine
DynamoDB Local is available as a download that is useful for developing and test applications without accessing the DynamoDB Web Service. The database is self-contained and runs on your computer.
Check out the above article, where I walk through in detail how to set up a local instance of DynamoDB, access it from applications, and the different modes it supports. I also cover the various GUI tools that can interact with the locally installed database instance.
Retrieving Data From DynamoDB
To retrieve data from DynamoDB, you have multiple querying options.
The Query operation is ideal for retrieving items that match specific criteria using partition and sort key values. Another option is the Scan operation, which filters results based on conditions but can be costly and impact performance for large tables.
As a rule of thumb, when querying data, you can consider that each record that you retrieve from the database has a direct cost attached to it. Limiting the items you retrieve has a direct impact on saving cost and also performance. Pagination helps with breaking down the items into smaller groups and loading them as required.
To learn more about different ways you can query DynamoDB and how to paginate data in your requests, check out the posts below.
- 5 Ways To Query Data From Amazon DynamoDB using .NET
- 3 Different Ways To Do Data Pagination from Amazon DynamoDB Using .NET
Improving Query Performance Using Indexes in DynamoDB
Amazon DynamoDB provides fast access to items in a table by specifying primary key values.
However, applications often require accessing data using alternate keys as well. In these cases, defining a second set of keys, a Secondary Index, is advantageous and beneficial to enable data access.
- Exploring Global Secondary Index: Advanced Querying in DynamoDB From .NET
- Improving Queries Using Local Secondary Index in DynamoDB with .NET
- Improving Query Performance in DynamoDB with Sparse Indexes and .NET
Writing Data To DynamoDB
DynamoDB provides two primary methods to write/modify data in a table: PutItem
and UpdateItem
. These are part of the Low-Level API IAmazonDynamoDB
. The High-Level API, IDynamoDBContext
wraps the two methods into a single SaveAsync
method.
By default, when using the .NET DynamoDB SDK, it serializes .NET classes, with a default constructor, as JSON objects. However, you can customize the data written into DynamoDB using Custom Converters.
When writing data to DynamoDB, it is essential to ensure data consistency when multiple users or applications access the same data simultaneously. Check out the below articles to explore the different ways you can ensure data consistency when writing to DynamoDB.
- How to Ensure Data Consistency with DynamoDB Condition Expressions From .NET Applications
- How to Implement Optimistic Locking in .NET for Amazon DynamoDB
DynamoDB and AWS Lambda
DynamoDB Triggers allow you to automatically invoke a Lambda function in response to specific actions on a DynamoDB table, such as item updates, inserts, or deletions.
DynamoDB Triggers enable you to build powerful and scalable applications that can automatically respond to changes in your DynamoDB tables without the need for any polling or manual intervention.
Check out the below articles to understand more about DynamoDB and AWS Lambda Triggers.
- DynamoDB Streams and AWS Lambda Trigger in .NET
- How to Handle Exceptions When Processing DynamoDB Stream Events in .NET Lambda Function
I hope this helps you get a good understanding of Amazon DynamoDB, and how to read/write to tables and integrate it with other AWS Services from your .NET application.
Rahul Nath Newsletter
Join the newsletter to receive the latest updates in your inbox.