2017-09-19 13 views
0

batchGetItemメソッドを使用してアイテムのxを取得し、ProjectionExpressionを使用して各アイテムのx属性を取得しています。AWS SDKを使用したDynamoDBの予約語PHP

$result = $client->batchGetItem(array(
    'RequestItems' => array(
     $table => array(
      'Keys' => $keys, 
      'ConsistentRead' => true, 
      'ProjectionExpression' => "id, name" 
     ), 
    ), 
)); 
$read_items = $result->getPath("Responses/{$table}"); 

は、しかし、私の項目のいくつかは、そのようなnameやDynamoDBの中で単語を予約されているtokenなどの属性を持っています。

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html

{"__type":"com.amazon.coral.validate#ValidationException","message":"Invalid ProjectionExpression: Attribute name is a r (truncated...) 
ValidationException (client): Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: name - {"__type":"com.amazon.coral.validate#ValidationException","message":"Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: name"} 
Filename: /var/app/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php 

私の知る限りではexpression attribute nameこのためsoultionですが、私はそれをbatchGetItemを行うための方法を見つけるのに苦労しています、誰かがSDK PHPを使用してそれを行うにはどのように小さな例をお願いすることができます理解してバージョン3.20.11?

答えて

1

ExpressionAttributeNamesの例を次に示します。

"#name" - 属性名のプレースホルダであり、実際の属性名はExpressionAttributeNamesの値に置き換えられます。

$result = $client->batchGetItem(array(
    'RequestItems' => array(
     $table => array(
      'Keys' => $keys, 
      'ConsistentRead' => true, 
      'ProjectionExpression' => "id, #name", 
      'ExpressionAttributeNames' => array('#name' => 'name'} 
     ), 
    ), 
)); 

link

+0

おかげで多くのことを参照してください:) – Berlin

関連する問題