Error: One or more parameter values were invalid--DynamoDb

Error: One or more parameter values were invalid--DynamoDb

我正在尝试使用以下代码更新 DynamoDb 中的 table..

$response = $client->updateItem(array(
    "TableName" => "PlayerInfo",
    "Key" => array(
        "PlayerId" => array('N' => '201503261435580358849074082'),
    ),
    "AttributeUpdates" => array(
        'PlayerPrice' => array(
            'N' => '5'
        ),
    ),
    "ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW
));

print_r($response);

但是,一个错误中断了它的执行。它说:

One or more parameter values were invalid: Only DELETE action is allowed 
when no attribute value is specified.

谁能帮我解决这个问题?

请求的 for 格式似乎缺少 'Action' 和 'Value' 参数。例如。以下对我有用:

$response = $client->updateItem(array(
    "TableName" => "PlayerInfo",
    "Key" => array(
        "PlayerId" => array('N' => '201503261435580358849074082'),
    ),
    "ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW,

    "AttributeUpdates" => array(
        'PlayerPrice' => array(
            'Action' => \Aws\DynamoDb\Enum\AttributeAction::PUT,
            'Value' => array('N' => '5'),
        )
    )
));
print_r($response);

您也可以使用 UpdateExpression 来实现相同的效果(UpdateExpressions 也比 AttributeUpdates 提供更大的灵活性,因此通常推荐使用它们):

$response = $client->updateItem(array(
    "TableName" => "PlayerInfo",
    "Key" => array(
        "PlayerId" => array('N' => '201503261435580358849074082'),
    ),
    "ReturnValues" => \Aws\DynamoDb\Enum\ReturnValue::ALL_NEW,

    "UpdateExpression" => "SET #pp = :val",
    "ExpressionAttributeNames" => array(
        "#pp" => "PlayerPrice",
    ),
    "ExpressionAttributeValues" => array(
        ':val' => array('N' => '5')
    )
));
print_r($response);