DynamoDB with PHP, error with update_item

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

com.amazon.coral.service # SerializationException Beginning of a list where it is not expected

I assume that something is wrong with the formatting of my array. I am using this documentation for reference.

The array I am 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"
        }
      }
    }
  }
}
+3
source share
1 answer

The "population" in AttributeUpdates is not correctly placed in the array. It should be the key to the element, not the element itself. "Value" and "Action" are part of an array element: The structure must 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"
      }
    }
  }
}

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')),
  )
);
0
source

All Articles