aws cli dynamo db(ValidationException)错误
问题描述:
我正在寻找使用python的boto3模块批量写入dynamodb的项目,我收到了这个。这是我第一次与aws cli或boto3合作过。该文档说,当有空值和可能不正确的数据类型时会出现验证异常错误,但是我已经玩过所有这些,但似乎没有工作。aws cli dynamo db(ValidationException)错误
dynamodb是否只喜欢一次写入25个项目?我如何控制这些批次?
我的要求:
client = boto3.client('dynamodb')
response = client.batch_write_item(RequestItems=batch_dict)
顶batch_dict的:
{'scraper_exact_urls': [{'PutRequest': {'Item': {'Sku': {'S': 'T104P3'},
'pps_id': {'N': '427285976'},
'scraper_class_name': {'S': 'scraper_class_name'},
'store_id': {'N': '1197386754'},
'updated_by': {'S': 'user'},
'updated_on': {'N': '1480714223'},
'updated_url': {'S': 'http://www.blah.com'}}}},
{'PutRequest': {'Item': {'Sku': {'S': 'T104P3'},
'pps_id': {'N': '427285976'},
'scraper_class_name': {'S': 'scraper_class_name'},
'store_id': {'N': '1197386754'},
'updated_by': {'S': 'user'},
'updated_on': {'N': '1480714223'},
'updated_url': {'S': 'http://www.blah.com'}}}},....
模式:
属性: “PPS_ID”=> \ AWS \ DynamoDb \枚举\型号:: NUMBER , “sku”=> \ Aws \ DynamoDb \ Enum \ Type :: STRING, “scraper_class_name”=> \ Aws \ DynamoDb \ Enum \ Type :: STRING, “store_id”=> \ Aws \ DynamoDb \ Enum \ Type :: NUMBER, “updated_url”=> \ Aws \ DynamoDb \ Enum \ Type :: STRING, “updated_by”=> \ Aws \ DynamoDb \ Enum \ :STRING, “updated_on”=> \ AWS \ DynamoDb \枚举\类型:: NUMBER, 字段: “PPS_ID”, “scraper_class_name”,
的错误:
ClientError: An error occurred (ValidationException) when calling the BatchWriteItem operation: 1 validation error detected: Value .... Map value must satisfy constraint: [Member must have length less than or equal to 25, Member must have length greater than or equal to 1]
答
的BatchWriteItem API一次处理25个项目。你可以使用下面的代码,改编自non-copying batching question,调用BatchWriteItem 25个块
def batch(iterable, n=1):
l = len(iterable)
for ndx in range(0, l, n):
yield iterable[ndx:min(ndx + n, l)]
client = boto3.client('dynamodb')
for x in batch(batch_dict['scraper_exact_urls'], 25):
subbatch_dict = {'scraper_exact_urls': x}
response = client.batch_write_item(RequestItems=subbatch_dict)
想我找到了答案在这里[链接](http://*.com/questions/31065900/how-to -write-more-than-25-items-rows-into-table-for-dynamodb) –
[如何为DynamoDB写入超过25个项目/行到表中](http://*.com/问题/ 31065900 /如何到写更比25项,行,成表换dynamodb) – LuFFy