Batch Delete DynamoDB Items

import boto3
from boto3.dynamodb.conditions import Key, Attr


dynamodb = boto3.resource('dynamodb', region_name='us-east-1')

table = dynamodb.Table('test_table')

scan = table.query(
    KeyConditionExpression=Key('schema_col').eq('col value')
)

with table.batch_writer() as batch:
    for item in scan['Items']:
        batch.delete_item(Key={'schema_col': item['schema_col'], 'schema_col_two': item['schema_col_two']})

Related Posts

Update Pip Packages With a Python Script
© 2014 - 2021 · Home ·
3E2BdqbtEy2SkEEbXW8Bv5snVEMPYxjvn3