So I'm attempting to sync Dynamodb tables using put_item. But I've run into an issue.
Invalid type for parameter Item.Artist, value: No One You Know, type: <class 'str'>, valid types: <class 'dict'>
From reading the documentation it looks like when using put_item it requires a dict so essentially something like this:
'{'Artist': {'S': 'No One You Know'},'SongTitle': {'S': 'Call Me Today'}}'
In order to add it correctly.
Here is my code:
#!/usr/bin/python3
import boto3
source = boto3.resource('dynamodb', 'us-east-1')
dest = boto3.client('dynamodb', 'us-west-2')
def sync(source, dest):
table = source.Table("myMusic")
scan_kwargs = {
'ProjectionExpression': "Artist, SongTitle"
}
done = False
start_key = None
while not done:
if start_key:
scan_kwargs['ExclusiveStartKey'] = start_key
response = table.scan(**scan_kwargs)
for item in response['Items']:
dest.put_item(TableName="myMusic", Item=item)
#print(item)
start_key = response.get('LastEvaluatedKey', None)
done = start_key is None
sync(source, dest)
So if I uncomment the print statement I get:
{'Artist': 'No One You Know', 'SongTitle': 'Call Me Today'}
Is there any way to sanitize the output or add the additional required 'S' or am I going about this the wrong way?