2016-12-02 4 views
0

Ich bin auf der Suche nach Batch-Artikel auf dynamodb mit Python Boto3-Modul zu schreiben, und ich bekomme das. Dies ist das erste Mal, dass ich jemals mit aws cli oder boto3 gearbeitet habe. Die Dokumentation besagt, dass Ausnahmefehler bei der Validierung auftreten, wenn leere Werte und mögliche falsche Datentypen vorhanden sind, aber ich habe mit all diesen gespielt und es scheint nicht zu funktionieren.aws cli dynamo db (ValidationException) Fehler

Kann dynamodb nur 25 Artikel gleichzeitig schreiben? Wie kann ich diese Chargen kontrollieren, wenn ja?

Meine Anfrage:

client = boto3.client('dynamodb') 
response = client.batch_write_item(RequestItems=batch_dict) 

oben 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'}}}},.... 

Schema:

Attribute: "pps_id" => \ Aws \ DynamoDB \ Enum \ Typ :: NUMBER , "sku" => \ Aws \ DynamoDb \ Enum \ Typ :: STRING, "scraper_class_name" => \ Aws \ DynamoDb \ Enum \ Typ :: STRING, "store_id" => \ Aws \ DynamoDb \ Enum \ Typ :: NUMBER, "updated_url" => \ Aws \ DynamoDb \ Enum \ Typ :: STRING, "updated_by" => \ Aws \ DynamoDb \ Enum \ Typ: : STRING, "updated_on" => \ Aws \ DynamoDB \ Enum \ Typ :: NUMBER, Felder: "pps_id", "scraper_class_name",

Der Fehler:

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] 
+0

denken, dass ich die Antwort hier [link] gefunden (http://stackoverflow.com/questions/31065900/how-to -write-more-than-25-items-rows-in-table-for-dynamodb) –

+0

Mögliches Duplikat von [Wie schreibe ich mehr als 25 Elemente/Zeilen in die Tabelle für DynamoDB?] (http://stackoverflow.com/ Fragen/31065900/How-to-Write-mehr-als-25-Elemente-Zeilen-in-Tabelle-für-Dynamodb) – LuFFy

Antwort

0

Die BatchWriteItem API arbeitet an 25 Elementen gleichzeitig. Sie könnten den folgenden Code verwenden, von der non-copying batching question angepasst, rufen BatchWriteItem auf 25 Artikel Brocken

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)