简体   繁体   中英

Python: Boto3, specifying attribute names for delete_item operation

The following code gives me an error:

dynamo_table.delete_item(Key={'segmentUuid': segment_id, 'value': value})

Error:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the DeleteItem operation: The provided key element does not match the schema

After doing some searching, I found that the issue is due to the sort key column being called value which is a reserved keyword in Dynamo. Unfortunately, boto3 doesn't seem to allow me to specify that using ExpressionAttributeName argument since it's unsupported for Key in delete_item operation. Can someone please suggest what I could do to resolve this issue?

value being a reserved word does make it confusing, but that error should have been

"Attribute name is a reserved keyword; reserved keyword: value"

in that case.

Your error occurs when you are trying to match an item by fields which are not hash/sort keys. So for this particular delete_item to work, you need a GSI with

segmentUuid → hash key

value → sort key

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