DynamoDb - Integer无法转换为String

时间:2016-01-12 12:19:54

标签: amazon-dynamodb

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

任何人都可以告诉新手。非常感谢。

2 个答案:

答案 0 :(得分:5)

你应该插入发电机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**

答案 1 :(得分:1)

img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#page {
    display: -ms-grid;
    display: grid;
    width: 100%;
    height: 400px;

    -ms-grid-rows: 50% 50%;
    grid-template-rows: 50% 50%;

    -ms-grid-columns: 60% 40%;
    grid-template-columns: 60% 40%;
}
#page #left {
    -ms-grid-column: 1;
    grid-column: 1;

    -ms-grid-row: 2; 
    grid-row: 2/4;

    -ms-grid-row-span: 2;

    background-color: #ffa08c;

    margin-right: 5px;
}
#page #righttop {
    -ms-grid-column: 2;
    grid-column: 2;

    -ms-grid-row: 1;
    grid-row: 1;

    background-color: #ffff64;

    margin-left: 5px;
    margin-bottom: 5px;
}
#page #rightbottom {        
    -ms-grid-column: 2;
    grid-column: 2;

    -ms-grid-row: 2;
    grid-row: 2;

    background-color: #8cffa0;

    margin-left: 5px;
    margin-top: 5px;
}