DynamoDB:ConditionalCheckFailedException, Status Code: 400; Error Code: ConditionalCheckFailedException
"message": "The conditional request failed (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ConditionalCheckFailedException; Request ID: HND4VSCK8HLM5NC08VDEV51CORVV4KQNSO5AEMVJF66Q9ASUAAJG)"
quick solution is here
Your goal is to save both records. There are 2 issues here
- With your choice of hash and range key it is impossible to save both records
The combination of hash and range key make a record unique. Event 1 and event 2 have the same values for hash and range key. Therefore the second put-item wil simply overwrite the first record.
- Your ConditionExpression prevents the replacement of record 1 by record 2
The ConditionExpression is evaluated just before putting a record. Your expression fails because when your event 2 is about to be inserted, DynamoDB discovers that a record with aggregateId “id1” already exists. The condition fails on "attribute_not_exists(aggregateId)", and you receive the ConditionalCheckFailedException This expression prevents overwriting of record 1 by record 2.
If you want to save both records you will have to come up with another choice of hash key and/or range key that better represents the unicity of your data item. You can not solve that with a ConditionExpression.
other solution
An item with that ID allready exists in the Table.
You need to create a unique ID for the item you try to add.
If you have any doubt regarding DynamoDB:ConditionalCheckFailedException then ask in comment
Top comments (1)
hello sir if i want to replace record 1 with record 2 how would i do it? or is there no way