Last active
November 14, 2021 10:20
-
-
Save jiimaho/0ecb08b0417fdcb2c71d23a405b852d8 to your computer and use it in GitHub Desktop.
SimpleDynamoDbQuery - whole
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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