2014-12-04 54 views
2

我正在使用AWS PHP SDK。我的RDS中有數百萬條包含大型JSON文件的記錄。我想將所有這些發送到DynamoDB,以便查詢和記錄,而不是轟炸我的RDS DB。將大型JSON字符串插入DynamoDB以進行查詢

不幸的是,當我嘗試添加新記錄(putItem)時,隨時都會出現此錯誤。你能幫我嗎?

<br /> 
<b>Fatal error</b>: Uncaught Aws\DynamoDb\Exception\DynamoDbException: AWS Error Code: SerializationException, Status Code: 400, AWS Request ID: IBB453LGDITFME8Q1G87AP9RCJVV4KQNSO5AEMVJF66Q9ASUAAJG, AWS Error Type: client, AWS Error Message: Start of list found where not expected, User-Agent: aws-sdk-php2/2.7.7 Guzzle/3.9.2 curl/7.28.1 PHP/5.5.10 
    thrown in <b>/Users/alex/Development/AWS/PHP SDK/Aws/Common/Exception/NamespaceExceptionFactory.php</b> on line <b>91</b><br /> 

這是我的PHP代碼:https://gist.github.com/nyalex/9004acbc4b2cabd5333b

回答

1

我想通了。我沒有爲putItem()輸入使用正確的數組格式。這裏是我的工作:

// Convert JSON for AWS 
$m = new Marshaler(); 

// Send to DynamoDB 
$result = $client->putItem(array(
    'TableName' => 'test', 
    'Item' => $m->marshalItem(
     array(
      'client_id'  => 100, 
      'order_id'  => '200', 
      'time' => time(), 
      'order' => $order_json 
     ) 
    ), 
    'ReturnConsumedCapacity' => 'TOTAL' 
));