本文介绍了使用Python删除DynamoDB的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用python(boto3)从DynamoDB中删除所有项目?

How can I delete all items from DynamoDB using python (boto3)?

我正在尝试这样做:

scan = table.scan()
with table.batch_writer() as batch:
  for each in scan['Items']:
    batch.delete_item(Key=each)

但是给我这个错误:

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


推荐答案

我找到了解决方案!我只是在表ID和搜索ID(compId)上安装了密钥,它就起作用了:)

I found a solution! I just mount the key with my table Id and search Id (compId) and It's worked :)

scan = table.scan()
with table.batch_writer() as batch:
    for each in scan['Items']:
        batch.delete_item(
            Key={
                'uId': each['uId'],
                'compId': each['compId']
            }
        )

这篇关于使用Python删除DynamoDB的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 01:01