Arun Kumar
Arun Kumar

Reputation: 33

DynamoDb Put item with a condition check on GSI

I have dynamodb table with GSI as the following:

ParentId#ChildName
2346#John
2388#Jerry

Now I want to add a new time to the table where parentId = 2388 and ChildName = Tom, before adding this item I want to make sure that the GSI doesn't already contains this combination "2388#Tom".

How can I achieve this, I was thinking of using a condition expression on GSI while doing the putItem operation, but I am not sure if dynamo db support condition expression on secondary indexes?

Any help will be highly appreciated.

Upvotes: 3

Views: 2379

Answers (1)

hunterhacker
hunterhacker

Reputation: 7132

You cannot do it with the table structure you have. GSIs are eventually consistent and can’t be used in a write, even with transactions. You can succeed if you manage the GSI propagation yourself to another item or, as this answer mentions, another table.

DynamoDBSaveExpression with conditional check on GSI

Upvotes: 1

Related Questions