2016-02-03 26 views
1

我試圖使用C#低級API更新DynamoDB表內的項目作爲記錄here傳遞一個空的AttributeValue到DynamoDb使用AWS底層API

這是我嘗試在實現這一目標:

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

回答

1

我不確定DynamoDB的類型是否可爲空。

如果您需要刪除屬性利用「SET#D =:數據,#T =:時間戳REMOVE#K」

+0

謝謝,這是有道理的因爲它是一個低級別的API – lisburnite