"Conditional query failed" while the condition works

I am using Amazonica, the Clojure library for writing to DynamoDB.

The following inserts the element into DynamoDB and updates its contents if it is called a second time, which is expected.

(ddb/put-item cred :table-name table-name :item payload) 

Now the following only inserts the element for the first time. Calling him a second time does nothing that I need.

 (ddb/put-item cred :table-name table-name :condition-expression "attribute_not_exists(clientId)" :item payload) 

However, with the latter, I get an error message:

The conditional request failed (Service: AmazonDynamoDBv2; Status code: 400; Error code: ConditionalCheckFailedException;

... which really does not make the code accessible. My CloudFormation template is very simple:

 "Resources": { "ClientTable": { "Type": "AWS::DynamoDB::Table", "Properties": { "AttributeDefinitions": [ { "AttributeName": "clientId", "AttributeType": "S" } ], "KeySchema": [ { "AttributeName": "clientId", "KeyType": "HASH" } ], "ProvisionedThroughput": { "ReadCapacityUnits": { "Ref": "ReadCapacityUnits" }, "WriteCapacityUnits": { "Ref": "WriteCapacityUnits" } }, "TableName": "ClientTable" } } } 

Did I miss something?

+5
source share
1 answer

Amazonica does not tacitly swallow the fact that the item has not been added. This throws an exception that you can catch if you want to do something. Perhaps you want to:

  • catch exception
  • make sure the error code matches this
  • ignore him if that happens.

To verify this, make sure that the same call really works for new keys.

+6
source

Source: https://habr.com/ru/post/1241858/


All Articles