1

I have a simple small table which I just want to update. Spent hours in the docs and testing things out, can't figure it out.

My table:

|environment |who|
-------------------
|ax          |tom|

Primary key is on 'environment'

All I want to do is to set 'who' to 'ben' where 'environment' = 'ax'.

I have tried both the legacy way of doing things, and the expression way. I also tried both the square brackets notation AWS uses in their docs, and the array() notation of php. Below are some of the ways I've tried doing it.

1:

$result = $client->updateItem(array(
    'ConditionExpression' => 'environment = :env',
    'ExpressionAttributeValues' => array(
        ':env' => array(
            'S' => 'environment'
        ),
        ':who' => array(
            'S' => $who
        )
    ),
    'Key' => array( // REQUIRED
        ':env' => array(
            'S' => $env
        )
    ),
    'ReturnValues' => 'UPDATED_NEW',
    'TableName' => 'areas',
    'UpdateExpression' => 'SET who = :who'
));

2:

$result = $client->updateItem([
    'ConditionExpression' => 'environment = :env',
    'ExpressionAttributeValues' => [
        ':env' => [
            'S' => 'environment'
        ],
        ':who' => [
            'S' => $who
        ]
    ],
    'Key' => [
        ':env' => [
            'S' => $env
        ]
    ],
    'ReturnValues' => 'UPDATED_NEW',
    'TableName' => 'areas',
    'UpdateExpression' => 'SET who = :who'
]);

3:

$result = $client->updateItem(array(
    'AttributeUpdates' => array(
        'who' => array(
            'Action' => 'PUT',
            'Value' => array(
                'S' => $who
            )
        )
    ),
    'Key' => array(
        'environment' => array(
            'S' => $env
        )
    ),
    'TableName' => 'areas'
));

Edit: This is the error I'm getting:

 SerializationException (client): Start of list found where not expected - {"__type":"com.amazon.coral.service#SerializationException","Message":"Start of list found where not expected"}'

Any help with this is much appreciated.

2
  • What error messages are you getting? Your post reads like a statement, not a question. What is the exact issue? Commented Jan 15, 2017 at 17:03
  • @MarkB I have updated my post to now include the error message I get. I get the same error with each of the different ways I try to do it. Commented Jan 15, 2017 at 18:22

1 Answer 1

2

I had encountered a similar problem. This is the code that i used and it worked.

$RegID = "abracadabra";
$tableName="DefaultDelivery";
$marshaler = new Marshaler();

$requested_delivery = '{"Packet0":{"PacketNo":"2","Quantity":"1000ml","Type":"Toned Milk"},"Packet2":{"PacketNo":"4","Quantity":"250ml","Type":"Toned Milk"}}';

$eav = $marshaler->marshalJson('
{
 ":RequestedDelivery" : '.$requested_delivery.'
}
');

$key = $marshaler->marshalJson('                                               
     {                                                                          
         "RegistrationID" : "'.$RegID.'"
     }                                                                          
');

$params = [
     'TableName' => "$tableName",
     'Key' => $key,
     'ExpressionAttributeValues' => $eav,
     'UpdateExpression' => 'SET RequestedDelivery = :RequestedDelivery',
     'ReturnValues' => 'UPDATED_NEW'
];

try {
    $result = $client->updateItem($params);
        echo "SUCCESS";
}
catch (DynamoDbException $e){
   echo "Unable to update Item : \n";
}
Sign up to request clarification or add additional context in comments.

1 Comment

I killed this project a while ago since it was a side project for work and it never got traction. I don't have the code anymore, nor the environment in which it ran. I am not sure if I am allowed to do this, but I will take your word for the solution and mark it as correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.