Created
June 18, 2020 02:54
-
-
Save awssimplified/bf82598643d52db4f8667027a29bbd18 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
#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