我是dynamoDB的新手,我正在努力填充我的DynamoDB表,我已经按如下方式定义了表:
$response = $DynamoDb->createTable([ 'TableName' => 'products', 'AttributeDefinitions' => [ [ 'AttributeName' => 'product_code', 'AttributeType' => 'N' ], [ 'AttributeName' => 'created_at', 'AttributeType' => 'N' ], ], 'KeySchema' => [ [ 'AttributeName' => 'product_code', 'KeyType' => 'HASH' ], [ 'AttributeName' => 'created_at', 'KeyType' => 'RANGE' ] ], 'ProvisionedThroughput' => [ 'ReadCapacityUnits' => 5, 'WriteCapacityUnits' => 6 ] ]);
并填充使用
$result = $DynamoDb->putItem([ 'TableName' => 'products', 'Item' => [ 'product_code' => ['N' => (int)$row[0]], 'created_at' => ['N' => (int)strtotime("now")] ] ]);
我一直在收到错误
Integer can not be converted to an String
任何人都可以告诉新手.非常感谢.
你应该插入发电机str值.如果'N'是行的类型,dynamo会将其转换为整数
"N": "string", $result = $DynamoDb->putItem([ 'TableName' => 'products', 'Item' => [ 'product_code' => ['N' => (str)$row[0]], 'created_at' => ['N' => (str)strtotime("now")] ] ]);
来自documantaion:
Item Each element in the Item map is an AttributeValue object. **Type: String to AttributeValue object map**