generate functionTue, 22 Nov 2022

code to add integer data in 'id' column in dynamodb table "person"

import boto3 import decimal # Helper class to convert a DynamoDB item to JSON. class DecimalEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, decimal.Decimal): if o % 1 > 0: return float(o) else: return int(o) return super(DecimalEncoder, self).default(o) dynamodb = boto3.resource('dynamodb', region_name='us-east-1') table = dynamodb.Table('person') response = table.scan() total = 0 for i in response['Items']: total = total + i['id'] print(total)

Questions about programming?Chat with your personal AI assistant