Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save PranavPhadke96/389ed852f2b313abf2863b67745ff11b to your computer and use it in GitHub Desktop.

Select an option

Save PranavPhadke96/389ed852f2b313abf2863b67745ff11b 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