I have a dynamoDB table called "sanskritOne" where the users upload words. I need a report of the count of total words collected. I have created a lambda function and I access the function URL to get the exact count.
import json, boto3
def lambda_handler(event, context):
dynamodb_resource = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb_resource.Table('sanskritOne')
total = 0
response = table.scan()
total += len(response['Items'])
while 'LastEvaluatedKey' in response:
response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
total += len(response['Items'])
print(f"Real-time item count: {total}")
return {
'statusCode': 200,
'body': json.dumps(total)
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.