I have written an async function which updates a dynamo-db table attribute value and here’s my code snippet
public async Task UpdateCount()
{
try
{
await _dynamoDbService.UpdateItemAsync(new UpdateItemRequest
{
TableName = _ledgerSummaryTableName,
ExpressionAttributeNames = new Dictionary<string, string> { { "#inv", "InvAttr"}, {"#Count", "DetCount"} },
ExpressionAttributeValues =
new Dictionary<string, AttributeValue> { { ":InvDetCount", new AttributeValue { N = "200" } }},
UpdateExpression = "SET #inv.#Count = :InvDetCount",
Key = new Dictionary<string, AttributeValue>
{
{"SubsId", new AttributeValue {S = "12345" },
{"ItemId", new AttributeValue {S = "1_98765"} }
}
});
}
catch (AmazonServiceException exception)
{
_logger.LogError($"Error: UpdateInvoiceDetailCount operation failed for IndexedLedgerSummary table. " + $"{exception.Message}");
throw new AuthenticationException(new Fault
{
Code = AccountErrorCode.UpdateLedgerSummaryItemFailed,
Message = "UpdateInvoiceDetailCount operation failed for IndexedLedgerSummary table. "
}, exception);
}
}
The expectation from the above code is, it will update the attribute DetCount with the desired value. I’m facing a scenario where the update is happening on the attribute (I see the new value updated) but still the function end of throwing the error that’s there in the catch block.
Can anyone help in understanding what am I missing here?
The exception that I’m getting is – The document path provided in the update expression is invalid for update
When I checked related to this error in aws documents, it says the error is thrown when the table doesn’t have this attribute to update. But post getting this error when I check the table, I see the attribute having correct value updated
6
The document path provided in the update expression is invalid for update
This exception means that you tried to update a JSON path without its root existing.
This means that InvAttr
doesn’t exist on the item your updating, leading to failure.
2