Skip to content

Instantly share code, notes, and snippets.

@jiimaho
Last active November 14, 2021 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiimaho/0ecb08b0417fdcb2c71d23a405b852d8 to your computer and use it in GitHub Desktop.
Save jiimaho/0ecb08b0417fdcb2c71d23a405b852d8 to your computer and use it in GitHub Desktop.
SimpleDynamoDbQuery - whole
// See https://aka.ms/new-console-template for more information
using System;
using System.Collections.Generic;
using System.Linq;
using Amazon;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using IAmazonDynamoDB client = new AmazonDynamoDBClient(RegionEndpoint.EUNorth1);
// ReSharper disable once StringLiteralTypo
var query = new QueryRequest
{
TableName = "customertestjim",
KeyConditionExpression = "CustomerId = :Id",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{
{ ":Id", new AttributeValue { S = "12345" }}
}
};
var queryResponse = await client.QueryAsync(query);
var row = queryResponse.Items.Single();
var customer = new { CustomerId = row["CustomerId"].S, Name = row["Name"].S };
Console.WriteLine($"5. Got a customer with id {customer.CustomerId} and name {customer.Name}");
Console.WriteLine("Done! Disposal of the client will now happen");
Console.WriteLine("Exiting");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment