DynamoDb-整数不能转换为字符串 [英] DynamoDb - Integer can not be converted to an String

查看:562
本文介绍了DynamoDb-整数不能转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是dynamoDB的新手,正在努力填充我的DynamoDB表,该表的定义如下:

I'm new to dynamoDB and am struggling to populate my DynamoDB table which I have defined the table as follows:

    $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

有人可以建议新手。非常感谢。

Can anybody please advise a newbie. Many thanks.

推荐答案

您应该将其插入dynamo str值。如果行的类型为'N',则dynamo会将其转换为整数

you should insert to dynamo str values. dynamo will convert it to integer if 'N' is the type of the row

"N": "string", 

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

来自文档幻想

Item

Each element in the Item map is an AttributeValue object.

**Type: String to AttributeValue object map**

这篇关于DynamoDb-整数不能转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆