Last active
January 5, 2021 17:55
-
-
Save bahrmichael/f0a8807706232ee0794d5f4e3ab862b4 to your computer and use it in GitHub Desktop.
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 boto3 | |
from uuid import uuid4 | |
dynamodb = boto3.resource('dynamodb') | |
table = dynamodb.Table('random-table') | |
# Create 100 records with a random partition key | |
for i in range(100): | |
item = {'pk': str(uuid4()), 'text': f"{i}"} | |
table.put_item(Item=item) | |
print(f"Inserted {item}") | |
# Read 3 records and print them with the consumed capacity | |
for i in range(3): | |
response = table.scan( | |
Limit=1, | |
ExclusiveStartKey={ | |
'pk': str(uuid4()) | |
}, | |
ReturnConsumedCapacity='TOTAL' | |
) | |
if response['Items']: | |
print({ | |
"Item": response['Items'][0], | |
"Capacity": response['ConsumedCapacity']['CapacityUnits'], | |
"ScannedCount": response['ScannedCount'] | |
}) | |
else: | |
print("Didn't find an item. Please try again.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment