using Amazon.DynamoDBv2.Model;
using System.Collections.Generic;
using System.Threading.Tasks;
private static AmazonDynamoDBClient client = new AmazonDynamoDBClient();
private static void Main()
string forumName = "Amazon DynamoDB";
string threadSubject = "DynamoDB Thread 2";
var job1 = FindRepliesForAThreadAsync(forumName, threadSubject);
var job2 = FindRepliesForAThreadSpecifyOptionalLimitAsync(forumName, threadSubject);
var job3 = FindRepliesForAThreadAsync(forumName, threadSubject);
var job4 = FindRepliesInLast25DaysWithConfigAsync(forumName, threadSubject);
var job5 = FindRepliesForAThreadAsync(forumName, threadSubject);
Task.WaitAll(job1, job2, job3, job4, job5);
catch (AmazonDynamoDBException ex) { Console.WriteLine(ex.Message); }
catch (AmazonServiceException ex) { Console.WriteLine(ex.Message); }
catch (Exception ex) { Console.WriteLine(ex.Message); }
Console.WriteLine("\n>>>>>> All jobs done! End of Program!");
private static async Task FindRepliesInLast25DaysWithConfigAsync(string forumName, string threadSubject)
Console.WriteLine("\nExecuting FindRepliesInLast25DaysWithConfigAsync()...");
string replyId = forumName + "#" + threadSubject;
DateTime twoWeeksAgoDate = DateTime.UtcNow - TimeSpan.FromDays(25);
string twoWeeksAgoString = twoWeeksAgoDate.ToString(AWSSDKUtils.ISO8601DateFormat);
QueryRequest queryRequest = new QueryRequest
KeyConditionExpression = " Id = :v_replyId AND ReplyDateTime > :v_interval ",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{ ":v_replyId", new AttributeValue{ S = replyId } },
{ ":v_interval", new AttributeValue { S = twoWeeksAgoString } }
ReturnConsumedCapacity = ReturnConsumedCapacity.TOTAL,
ProjectionExpression = "Id, ReplyDateTime, PostedBy",
QueryResponse queryResponse = await client.QueryAsync(queryRequest).ConfigureAwait(true);
foreach (Dictionary<string, AttributeValue> item in queryResponse.Items)
Console.WriteLine("--End of FindRepliesInLast25DaysWithConfigAsync().\n");
private static async Task FindRepliesForAThreadSpecifyOptionalLimitAsync(string forumName, string threadSubject)
Console.WriteLine("\nExecuting FindRepliesForAThreadSpecifyOptionalLimitAsync()...");
string replyId = forumName + "#" + threadSubject;
Dictionary<string, AttributeValue> lastKeyEvaluated = null;
QueryRequest queryRequest = new QueryRequest
KeyConditionExpression = " Id = :v_replyId ",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{ ":v_replyId", new AttributeValue{ S = replyId }}
ReturnConsumedCapacity = ReturnConsumedCapacity.TOTAL,
ExclusiveStartKey = lastKeyEvaluated
QueryResponse queryResponse = await client.QueryAsync(queryRequest).ConfigureAwait(true);
foreach (Dictionary<string, AttributeValue> item in queryResponse.Items)
} while (lastKeyEvaluated != null && lastKeyEvaluated.Count != 0);
Console.WriteLine("--End of FindRepliesForAThreadSpecifyOptionalLimitAsync().\n");
private static async Task FindRepliesForAThreadAsync(string forumName, string threadSubject)
Console.WriteLine("\nExecuting FindRepliesForAThreadAsync()...");
string replyId = forumName + "#" + threadSubject;
QueryRequest queryRequest = new QueryRequest()
ReturnConsumedCapacity = ReturnConsumedCapacity.TOTAL,
KeyConditionExpression = "Id = :v_replyId",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{ ":v_replyId", new AttributeValue { S = replyId }}
QueryResponse queryResponse = await client.QueryAsync(queryRequest).ConfigureAwait(true);
foreach (Dictionary<string, AttributeValue> item in queryResponse.Items)
Console.WriteLine("--End of FindRepliesForAThreadAsync().\n");
private static void PrintAttributes(Dictionary<string, AttributeValue> Items)
foreach (KeyValuePair<string, AttributeValue> item in Items)
Console.WriteLine("Key=" + item.Key + ", Value=" +
(item.Value.SS == null ? "" : string.Join(", ", item.Value.SS.ToArray())) +
(item.Value.NS == null ? "" : string.Join(", ", item.Value.NS.ToArray()))