-
-
Save abdullah353/05ee6776e6d70004ae6d6495eea8240c to your computer and use it in GitHub Desktop.
Query on an involved table, using boto3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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