Amazon dynamodb DynamoDb-整数不能转换为字符串

Amazon dynamodb DynamoDb-整数不能转换为字符串,amazon-dynamodb,Amazon Dynamodb,我是dynamoDB新手,正在努力填充我的dynamoDB表,我将该表定义如下: $response = $DynamoDb->createTable([ 'TableName' => 'products', 'AttributeDefinitions' => [ [ 'AttributeName' => 'product_code', 'Att

我是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

谁能给新手提个建议吗。非常感谢。

您应该在dynamo str中插入值。如果“N”是行的类型,dynamo将其转换为整数

"N": "string", 

 $result = $DynamoDb->putItem([
          'TableName' => 'products',
            'Item' => [
              'product_code' => ['N'  =>  (str)$row[0]],
              'created_at' => ['N' => (str)strtotime("now")]
            ]
        ]);
发件人:


您应该向dynamo str插入值。如果“N”是行的类型,dynamo将其转换为整数

"N": "string", 

 $result = $DynamoDb->putItem([
          'TableName' => 'products',
            'Item' => [
              'product_code' => ['N'  =>  (str)$row[0]],
              'created_at' => ['N' => (str)strtotime("now")]
            ]
        ]);
发件人:

$result = $DynamoDb->putItem([
      'TableName' => 'products',
        'Item' => [
          'product_code' => ['N'  =>  (string)$row[0]],
          'created_at' => ['N' => (string)time()]
        ]
    ]);