forked from aws-samples/aws-dynamodb-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteItemConditional.cs
54 lines (48 loc) · 1.62 KB
/
DeleteItemConditional.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Amazon;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
namespace DotnetSamples.WorkingWithItems
{
public class DeleteItemConditional
{
private readonly IAmazonDynamoDB amazonDynamoDB;
public DeleteItemConditional()
{
amazonDynamoDB = new AmazonDynamoDBClient(RegionEndpoint.USWest2);
}
public DeleteItemConditional(IAmazonDynamoDB amazonDynamoDB)
{
this.amazonDynamoDB = amazonDynamoDB;
}
public async Task ServiceClientExampleAsync()
{
try
{
var request = new DeleteItemRequest
{
TableName = "RetailDatabase",
Key = new Dictionary<string, AttributeValue>
{
{"pk", new AttributeValue {S = "[email protected]"} },
{"sk", new AttributeValue {S = "metadata"} }
},
ConditionExpression = "address.postalcode = :val",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{
{ ":val", new AttributeValue("98260") }
}
};
var response = await amazonDynamoDB.DeleteItemAsync(request);
Console.WriteLine($"DeleteItemConditional succeeded.");
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
throw;
}
}
}
}