Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created November 15, 2024 01:03
Show Gist options
  • Save mark-cooper/9a121e3647b154ad89a829fa078f15b2 to your computer and use it in GitHub Desktop.
Save mark-cooper/9a121e3647b154ad89a829fa078f15b2 to your computer and use it in GitHub Desktop.
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('TABLE_NAME')
def update_items(items):
for item in items:
table.update_item(
Key={
'KEY': item['KEY']
},
UpdateExpression="SET FIELD = :val",
ExpressionAttributeValues={
':val': 'VALUE'
}
)
response = table.scan()
update_items(response['Items'])
while 'LastEvaluatedKey' in response:
response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
update_items(response['Items'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment