テストように実行したバッチ処理にてDynamoDBに2万件以上のレーコドができてしまった。コンソールで削除するのも時間の無駄なので簡単lambdaにて削除しました。
こんなに簡単ですね!
import boto3
from botocore.exceptions import ClientError
dynamodb = boto3.resource('dynamodb', region_name='ap-northeast-1')
table = dynamodb.Table('my_table_name')
def deleteItem(hashKey, rangeKey):
try:
response = table.delete_item(
Key={
'my_hash': hashKey,
'my_range': rangeKey
}
)
except ClientError as e:
raise
else:
print("DeleteItem succeeded:")
def lambda_handler(event, context):
pe = "my_hash, my_range" #projection fields
response = table.scan(
ProjectionExpression=pe,
)
for i in response['Items']:
hashKey = i["my_hash"]
rangeKey = i["my_range"]
deleteItem(hashKey,rangeKey)
while 'LastEvaluatedKey' in response:
response = table.scan(
ProjectionExpression=pe,
ExclusiveStartKey=response['LastEvaluatedKey']
)
for i in response['Items']:
hashKey = i["my_hash"]
rangeKey = i["my_range"]
deleteItem(hashKey,rangeKey)
return 'Successfully complete delete all items from table.'