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

Passing a null AttributeValue into DynamoDb using AWS low level API

我正在尝试使用 C# 低级别 API 更新 DynamoDB table 中的项目,如记录 here

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

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
});

此代码工作正常,但是当 MyKey 为空字符串时会出现问题。当它为空时,我收到以下错误:

Amazon.DynamoDBv2.AmazonDynamoDBException: ExpressionAttributeValues contains invalid value: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes for key :MyKey

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

new AttributeValue{NULL = true}

然而,这会将值设置为 True

的字符串文字

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

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