Skip to content

Instantly share code, notes, and snippets.

@sunnycyk
Created December 17, 2016 05:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnycyk/02e2367004c7ade0f65eebc39fb97159 to your computer and use it in GitHub Desktop.
Save sunnycyk/02e2367004c7ade0f65eebc39fb97159 to your computer and use it in GitHub Desktop.
dynamodb notes
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('table')
response = table.scan(
ProjectionExpression='#k,#s',
ExpressionAttributeNames={
'#k' : 'id', #partition key
'#s' : 'sortkey' #sort key
}
)
items = response['Items']
for item in items:
response = table.update_item(
Key=item,
UpdateExpression='SET #s = :status, #d = :del',
ExpressionAttributeNames={
'#s' : 'status',
'#d' : 'deleted'
},
ExpressionAttributeValues={
':status' : 'live',
':del' : False
}
)
@andresvia
Copy link

Hi @sunnycyk does this take care of pagination?

@repinel
Copy link

repinel commented Sep 16, 2019

@andresvia no. You need to check if LastEvaluatedKey is in the scan response to know if the results have been paginated. Then the last evaluated key should be provided in the next scan as ExclusiveStartKey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment