【问题标题】:Error: One or more parameter values were invalid--DynamoDb错误:一个或多个参数值无效--DynamoDb
【发布时间】:2015-03-31 09:22:20
【问题描述】:

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

$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.

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: amazon-dynamodb


    【解决方案1】:

    请求的 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);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多