Question

I'm trying to update a table in my DynamoDB tables using the PHP SDK. Here's the error:

com.amazon.coral.service#SerializationException Start of list found where not expected

I'm guessing there is something wrong with the formatting of my array. I'm using this documentation for reference.

The Array I'm sending:

array(3) {
  ["TableName"]=>
  string(7) "teacher"
  ["Key"]=>
  array(1) {
    ["HashKeyElement"]=>
    array(1) {
      ["S"]=>
      string(36) "97770A6A-EF06-AF4A-3E30-87DAC0237F6D"
    }
  }
  ["AttributeUpdates"]=>
  array(1) {
    [0]=>
    array(2) {
      ["population"]=>
      array(1) {
        ["Action"]=>
        string(3) "ADD"
      }
      ["Value"]=>
      array(1) {
        ["SS"]=>
        array(1) {
          [0]=>
          string(36) "97770A6A-EF06-AF4A-3E30-87DAC0237F6D"
        }
      }
    }
  }
}
Was it helpful?

Solution

The "population" in AttributeUpdates is incorrectly placed in the array. It should be a key to the element and not the element itself. The "Value" and "Action" are both part of the array element: The structure should be:

array(3) {
  ["TableName"]=>
  string(7) "teacher"
  ["Key"]=>
  array(1) {
    ["HashKeyElement"]=>
    array(1) {
      ["S"]=>
      string(36) "97770A6A-EF06-AF4A-3E30-87DAC0237F6D"
    }
  }
  ["AttributeUpdates"]=>
  array(1) {
    ["population"]=>
    array(1) {
      ["Value"]=>
      array(2) {
        ["SS"]=>
        array(1) {
          [0]=>
          string(36) "97770A6A-EF06-AF4A-3E30-87DAC0237F6D"
        }
        ["Action"]=>
        string(3) "ADD"
      }
    }
  }
}

The source:

$updateOptions = array(
  'TableName'    => 'teacher',
  'Key'          => array(
      'HashKeyElement'  => array('S' => '97770A6A-EF06-AF4A-3E30-87DAC0237F6D'),
  ),
  'AttributeUpdates' => array(
      'population'    => array('Value' => array('SS' => array('97770A6A-EF06-AF4A-3E30-87DAC0237F6D'), 'Action' => 'ADD')),
  )
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top