from __future__ import print_function # Python 2/3 compatibility import json import boto3 from pprint import pprint from decimal import Decimal # AWS_ACCESS = "" # AWS_SECRET = "" AWS_REGION = "eu-west-3" TABLE_NAME = "users" # Build New dict with Correct Datatypes """The method to deserialize the DynamoDB data types. :param value: A DynamoDB value to be deserialized to a pythonic value. Here are the various conversions: DynamoDB Python -------- ------ {'NULL': True} None {'BOOL': True/False} True/False {'N': str(value)} Decimal(str(value)) {'S': string} string {'B': bytes} Binary(bytes) {'NS': [str(value)]} set([Decimal(str(value))]) {'SS': [string]} set([string]) {'BS': [bytes]} set([bytes]) {'L': list} list {'M': dict} dict :returns: The pythonic value of the DynamoDB type. """ # https://boto3.amazonaws.com/v1/documentation/api/latest/_modules/boto3/dynamodb/types.html with open(TABLE_NAME+'.json', 'r') as f: distros_dict = json.load(f) dynamodb = boto3.resource( 'dynamodb', # aws_secret_access_key=AWS_SECRET, # aws_access_key_id=AWS_ACCESS, region_name=AWS_REGION) table = dynamodb.Table(TABLE_NAME) mylist = distros_dict['Items'] for mydict in mylist: boto3.resource('dynamodb') deserializer = boto3.dynamodb.types.TypeDeserializer() python_data = {k: deserializer.deserialize(v) for k, v in mydict.items()} pprint(python_data) response = table.put_item(Item=python_data)