-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathquery_begins_with.py
18 lines (15 loc) · 1.04 KB
/
query_begins_with.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import boto3, json
from boto3.dynamodb.conditions import Key
# boto3 is the AWS SDK library for Python.
# The "resources" interface allows for a higher-level abstraction than the low-level client interface.
# For more details, go to http://boto3.readthedocs.io/en/latest/guide/resources.html
dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
table = dynamodb.Table('RetailDatabase')
# When making a Query API call, we use the KeyConditionExpression parameter to specify the partition key on which we want to query.
# We're using the Key object from the Boto3 library to specify that we want the attribute name ("pk")
# to equal "[email protected]" by using the ".eq()" method. Further we get all of those items that have a sort key using the
# "begins_with()" method to look for "meta::".
resp = table.query(KeyConditionExpression=Key('pk').eq('[email protected]') & Key('sk').begins_with('meta::'))
print("The query returned the following items:")
for item in resp['Items']:
print(json.dumps(item, indent=4, sort_keys=True))