简体   繁体   中英

delete record from dynamodb using boto3 when sort key is not known

I have to delete record using PK and SK but I don't know SK whole value for example

on insertion

SK = 'VR#'+current_time

and PK = 'AC#'+ID

so NOW I want to delete a item and doing this

def delete_record(key):
    try:
        table = get_dynamodb_table()
        response = table.delete_item(
            Key={
                 "PK" : 'AC#12131',
                 "SK" : 'VR#'
         }      
        )
    except Exception as err:
        print(err)
        return False
    else:
        return response

Now I am getting 200 from dynamo but item is not being deleted..

You're getting a 200 because it did what you asked, which is to make sure that item doesn't exist. It's not an error to delete what doesn't exist.

You cannot delete an item without specifying its primary key, which is the combo of PK and SK both.

What you can do is a Query to fetch the primary key (provide the PK and learn the SK) then you can issue the delete.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM