Skip to content

Instantly share code, notes, and snippets.

@abdullah353
Forked from numberoverzero/query_boto3.py
Created December 14, 2016 15:39
Show Gist options
  • Save abdullah353/05ee6776e6d70004ae6d6495eea8240c to your computer and use it in GitHub Desktop.
Save abdullah353/05ee6776e6d70004ae6d6495eea8240c to your computer and use it in GitHub Desktop.
Query on an involved table, using boto3
import arrow
import boto3
import uuid
dynamodb = boto3.client('dynamodb')
some_id = uuid.uuid4()
some_time = arrow.now()
request = {
'ConsistentRead': False,
'ExpressionAttributeNames': {
'#n0': 'joined', '#n2': 'not_projected', '#n3': 'name', '#n5': 'date'},
'ExpressionAttributeValues': {
':v4': {'S': str(some_id)},
':v6': {'S': some_time.isoformat()},
':v1': {'S': 'today'}},
'FilterExpression': '(#n0 = :v1)',
'KeyConditionExpression': '((#n3 = :v4) AND (#n5 = :v6))',
'ProjectionExpression': '#n2',
'ScanIndexForward': True,
'Select': 'SPECIFIC_ATTRIBUTES',
'TableName': 'CustomTableName'
}
# Don't forget to handle retries and continuation tokens (LastEvaluatedKey)
results = dynamodb.query(**request)
for item in results["Items"]:
print("Now just load these serialized values:")
print(item["name"], item["date"], item["not_modeled"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment