Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save awssimplified/bf82598643d52db4f8667027a29bbd18 to your computer and use it in GitHub Desktop.
Save awssimplified/bf82598643d52db4f8667027a29bbd18 to your computer and use it in GitHub Desktop.
#IAM Permission needed: dynamodb:query
import json
import sys
import boto3
from boto3.dynamodb.conditions import Key, Attr
dynamodb = boto3.resource('dynamodb')
def lambda_handler(event, context):
table = dynamodb.Table('Countries')
queryCount = 1
#Make Initial Query
response = table.query(KeyConditionExpression=Key('CountryName').eq('USA'))
#Extract the Results
items = response['Items']
for item in items:
countryName = item['CountryName']
state = item['State']
size = sys.getsizeof(item)
print(str(queryCount) + ' - ' + countryName + ' - ' + state + ' - ' + str(size))
queryCount += 1
while 'LastEvaluatedKey' in response:
print('---------')
key = response['LastEvaluatedKey']
response = table.query(KeyConditionExpression=Key('CountryName').eq('USA'), ExclusiveStartKey=key)
items = response['Items']
for item in items:
countryName = item['CountryName']
state = item['State']
size = sys.getsizeof(item)
print(str(queryCount) + ' - ' + countryName + ' - ' + state + ' - ' + str(size))
queryCount += 1
print("---------")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment