我的代码如下是从表名中删除内容details
下面的代码将根据Capacitydynamodb 删除一些项目,该项目工作正常
如何删除所有项目
import boto3
def lambda_handler(event, context):
try:
table_name = 'details'
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(table_name)
scan = table.scan()
with table.batch_writer() as batch:
for each in scan['Items']:
batch.delete_item(
Key={
'id': each['id']
}
)
except Exception as e:
print (e)
while我用带有标志条件的循环编写。
import boto3
def lambda_handler(event, context):
try:
flag = False
table_name = 'details'
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(table_name)
scan = table.scan()
while True:
with table.batch_writer() as batch:
for each in scan['Items']:
if each is not None:
batch.delete_item(
Key={
'id': each['id']
}
)
else:
Flag = True
except Exception as e:
print (e)
翻阅古今
互换的青春
相关分类