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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With