Search code examples
asp.net-coreamazon-dynamodbaws-sdk-net

Table.PutItemAsync of AWSSDK.DynamoDBv2 always returns null


In .net core 2.1 application I am adding a new record into DynamoDB table using Table.PutItemAsync of AWSSDK.DynamoDBv2 (v3.3.101.18) library:

var doc = await _table.PutItemAsync(document);

I can see that the record is successfully added in AWS Console, but it always returns null whereas the expected return value should be a Document:

public Task<Document> PutItemAsync(Document doc, CancellationToken cancellationToken = default);

I wonder if I am missing something obvious?


Solution

  • You need to specify the ReturnValues enum type in your PutItemOperationConfig and include this config in your request. The default is to return None. If you specify ReturnValues.AllOldAttributes (the only other option for this request), then you will get back a document with the old item's attributes if you overwrote an item or an empty item if you added a new item.

            var putItemOperationConfig = new PutItemOperationConfig()
            {
                ReturnValues = ReturnValues.AllOldAttributes
            };