I have a dynamo db, with a primary key composed of id and a sort key. I want to delete bunch of records (still need to figure out how to do it batch), and here is a starting point - sample code below.
Theoretically there shouldn't be any duplicates in the table, but is there a way to check, if there is a duplicate in dynamodb, before deleting? Or a query to get the count before deleting an item?
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('sometable')
response = table.delete_item(
Key={
'id': 'abcd',
'sortKey': 'efgh'
}
)
status_code = response['ResponseMetadata']['HTTPStatusCode']
From the docs:
When you create a table, in addition to the table name, you must specify the primary key of the table. The primary key uniquely identifies each item in the table, so that no two items can have the same key.
This fact is pretty fundamental for just about anything in DynamoDB, so you can rest assured that no duplicate records with the same value of the primary key ever exist in a DynamoDB table.