使用 AWS 低级 API 将 null AttributeValue 传递到 DynamoDb

lis*_*ite 2 c# amazon-web-services amazon-dynamodb aws-sdk

我正在尝试使用 C# 低级 API 更新 DynamoDB 表中的项目,如此处所述

这是我实现这一目标的尝试:

var response = DynamoClientProvider.Current.UpdateItem(new UpdateItemRequest
{
    TableName = "MyTable",
    Key = {{"TableId", new AttributeValue {S = "12345"}}},
    ExpressionAttributeNames =
    {
        {"#T","Timestamp"},
        {"#D","Data"}
        {"#K","MyKey"}
    },
    ExpressionAttributeValues =
    {
        {":Timestamp", new AttributeValue("2016-2-3 00:00:00.000")},
        {":Data", new AttributeValue("some data")}
        {":MyKey", new AttributeValue("some other data")}
    },
    UpdateExpression = "SET #D = :Data, #T = :Timestamp, #K = :MyKey",
    ConditionExpression = "attribute_not_exists (Data)",
    ReturnValues = ReturnValue.ALL_OLD
});
Run Code Online (Sandbox Code Playgroud)

MyKey该代码工作得很好,但是当为空字符串时存在问题。当它为空时,我收到以下错误:

Amazon.DynamoDBv2.AmazonDynamoDBException:ExpressionAttributeValues 包含无效值:提供的 AttributeValue 为空,必须恰好包含键支持的数据类型之一:MyKey

因此,我尝试传入 null,AttributeValue以便通过将其设置为以下内容来删除本例中的属性:

new AttributeValue{NULL = true}
Run Code Online (Sandbox Code Playgroud)

然而,这会将值设置为字符串文字True

pre*_*ion 5

我不确定 DynamoDB 的类型是否可以为空。

如果需要删除属性,请使用 'SET #D = :Data, #T = :Timestamp REMOVE #K'