小编mcg*_*osh的帖子

无效类型参数类 str,有效类型类 dict

因此,我尝试使用 put_item 同步 Dynamodb 表。但我遇到了一个问题。

Invalid type for parameter Item.Artist, value: No One You Know, type: <class 'str'>, valid types: <class 'dict'>
Run Code Online (Sandbox Code Playgroud)

从阅读文档来看,使用 put_item 时它需要一个字典,所以本质上是这样的:

'{'Artist': {'S': 'No One You Know'},'SongTitle': {'S': 'Call Me Today'}}'
Run Code Online (Sandbox Code Playgroud)

以便正确添加。

这是我的代码:

#!/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 …
Run Code Online (Sandbox Code Playgroud)

python-3.x boto3

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

boto3 ×1

python-3.x ×1