I am using Amazonica, a Clojure library to write to DynamoDB.
The following inserts an item into DynamoDB and updates its content if called a second time, which is expected.
(ddb/put-item cred
:table-name table-name
:item payload)
Now, the following inserts an item only the first time. Calling it a second time doesn't do anything, which is what I need.
(ddb/put-item cred
:table-name table-name
:condition-expression "attribute_not_exists(clientId)"
:item payload)
However with the latest I am getting an error:
The conditional request failed (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ConditionalCheckFailedException;
... which doesn't really make the code deliverable. 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"
}
}
}
Am I missing something?
ProvisionedThroughputExceededException. Message: You exceeded your maximum allowed provisioned throughput for a table or for one or more global secondary indexes. To view performance metrics for provisioned throughput vs. consumed throughput, open the Amazon CloudWatch console . Example: Your request rate is too high.
The DynamoDBMapper class is the entry point to Amazon DynamoDB. It provides access to a DynamoDB endpoint and enables you to access your data in various tables. It also enables you to perform various create, read, update, and delete (CRUD) operations on items, and run queries and scans against tables.
In Amazon DynamoDB, an item is a collection of attributes. Each attribute has a name and a value. An attribute value can be a scalar, a set, or a document type. For more information, see Amazon DynamoDB: How it works. DynamoDB provides four operations for basic create, read, update, and delete (CRUD) functionality.
Amazonica is not silently swallowing the fact that the item was not added. It's throwing an exception that you can catch in case you want to do something about it. Perhaps you want to:
To test this, make sure that the same call does indeed work for new keys.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With