AWS PHP SDK问题(DynamoDB)问题、PHP、AWS、DynamoDB

2023-09-11 11:27:13 作者:逞英雄

近日DynamoDB公布的文件类型(列表或地图)。在这里看到:http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModel.DataTypes 或在这里: http://www.allthingsdistributed.com/2014/10/文档模型dynamodb.html

Recently DynamoDB released document types (list or map). See here: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModel.DataTypes or here: http://www.allthingsdistributed.com/2014/10/document-model-dynamodb.html

现在正在试图存储在DynamoDB以下数组

Now am trying to store the following array in DynamoDB

array("key"=>"value")

我使用PHP SDK 2.7.0和2.7.2和3.0.0的测试版(尝试了所有这些解决我的问题,每次都是同样的问题)。低于我的code存储两个字符串完美的作品

require ("aws2.7.0/aws-autoloader.php");
use Aws\DynamoDb\DynamoDbClient;
$client = DynamoDbClient::factory(array(
                'key'    => 'KEY',
                'secret' => 'SECRET',
                'region' => 'eu-west-1'
));

$result = $client->putItem(array(
    'TableName' => 'requests-test',
    'Item' => array(
        'messageId'      => array('S' => "test-message1"),
        'data'      => array('S' => "message-data-here"),
        ),
    )
));

现在我想存储一个简单的数组与地图数据的类型,而不是字符串:

Now I am trying to store a simple array with Map data type instead of string:

require ("aws2.7.0/aws-autoloader.php");
use Aws\DynamoDb\DynamoDbClient;
$client = DynamoDbClient::factory(array(
                'key'    => 'KEY',
                'secret' => 'SECRET',
                'region' => 'eu-west-1'
));

$result = $client->putItem(array(
    'TableName' => 'requests-test',
    'Item' => array(
        'messageId'      => array('S' => "test-message1"),
        'data'      => array('M' => array("key"=>"value")),
        ),
    )
));

这将导致以下错误:

致命错误:未捕获的AWS \ DynamoDb \异常\ DynamoDbException:AWS   错误code:SerializationException,状态code:400,AWS请求ID:   8H9URPVBNPCTG4VALA62XXXX3NVV4KQNSO5AEMVJF66Q9ASUAYGX,AWS错误类型:   客户端,AWS错误消息:预计空,用户代理:   AWS-SDK-PHP2 / 2.7.0狂饮/ 3.9.2卷曲/ 7.36.0 PHP / 28年5月3日抛出   /path/aws2.7.0/Aws/Common/Exception/NamespaceExceptionFactory.php   上线91

Fatal error: Uncaught Aws\DynamoDb\Exception\DynamoDbException: AWS Error Code: SerializationException, Status Code: 400, AWS Request ID: 8H9URPVBNPCTG4VALA62XXXX3NVV4KQNSO5AEMVJF66Q9ASUAYGX, AWS Error Type: client, AWS Error Message: Expected null, User-Agent: aws-sdk-php2/2.7.0 Guzzle/3.9.2 curl/7.36.0 PHP/5.3.28 thrown in /path/aws2.7.0/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91

AWS PHP SDK 2.7.0及以上应支持地图和列表类型:的 https://github.com/aws/aws-sdk-php/releases/tag/2.7.0

AWS PHP SDK 2.7.0 and above should support Map and List type: https://github.com/aws/aws-sdk-php/releases/tag/2.7.0

我如何可以存储在DynamoDB阵列?是否有可能还与当前的软件开发工具包在那里 - 或者他们需要发布的更新完全支持这些新的数据类型?或者是我的code中的问题?

How can I store arrays in DynamoDB? Is it possible yet with the current SDKs out there - or do they need to release an update to fully support those new data types? Or is the issue in my code?

我会非常感谢任何意见或可能的解决方案。在此先感谢!

I'd be really grateful for any comments or possible solutions. Thanks in advance!

推荐答案

在DynamoDB,文档(列表或地图)的值应该是一个属性值。

In DynamoDB, the value of a document (list or map) should be an attribute value.

'Item' => array(
    'messageId'      => array('S' => "test-message1"),
    'data'      => array('M' => array("key"=> 
                                          array('S' => "value"))),
    ),
)

同样在列表中,你会这样的:

Similarly in a list, you would have this:

array('L' => array( 
           array('S' => "key"), array('S' => "value")));

我希望这有助于!

I hope this helps!

 
精彩推荐
图片推荐