Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to update a table in DynamoDb with the following code..

$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);

However, an error interrupts its execution. It says:

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

Could anybody help me with this issue?

like image 255
Bhavik Joshi Avatar asked Mar 26 '15 09:03

Bhavik Joshi


1 Answers

Looks like the for format of the request was missing the 'Action' and 'Value' parameters. E.g. the following is working for me:

$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);

You can also use an UpdateExpression to achieve the same effect (UpdateExpressions also provide greater flexibility than AttributeUpdates so they are generally recommended):

$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);
like image 200
Johnny Wu Avatar answered Sep 29 '22 08:09

Johnny Wu