title: DynamoDB - Update item by GSI (PHP)
body: <p>I'm trying to update an item using a Global Secondary Index. My table definition is listed below. I am new to DynamoDb.</p>
  
  <pre><code>    $response = $this-&gt;client-&gt;createTable([
          'TableName' =&gt; 'rawproducts_products',
          'AttributeDefinitions' =&gt; [
              [
                  'AttributeName' =&gt; 'product_code',
                  'AttributeType' =&gt; 'N'
              ],
              [
                  'AttributeName' =&gt; 'token',
                  'AttributeType' =&gt; 'S'
              ],
              [
                  'AttributeName' =&gt; 'processed_at',
                  'AttributeType' =&gt; 'N'
              ],
              [
                  'AttributeName' =&gt; 'created_at',
                  'AttributeType' =&gt; 'N'
              ]                    
          ],
          'KeySchema' =&gt; [
              [
                  'AttributeName' =&gt; 'product_code',
                  'KeyType' =&gt; 'HASH' 
              ],
              [
                  'AttributeName' =&gt; 'token',
                  'KeyType' =&gt; 'RANGE' 
              ]
          ],
          'LocalSecondaryIndexes' =&gt; [
              [
                  'IndexName' =&gt; 'ProductCodeProcessedIndex',
                  'KeySchema' =&gt; [
                      ['AttributeName' =&gt; 'product_code', 'KeyType' =&gt; 'HASH'],
                      ['AttributeName' =&gt; 'processed_at', 'KeyType' =&gt; 'RANGE']
                  ],
                  'Projection' =&gt; [
                      'ProjectionType' =&gt; 'KEYS_ONLY',
                  ],
              ],
              [
                  'IndexName' =&gt; 'ProductCodeCreatedIndex',
                  'KeySchema' =&gt; [
                      ['AttributeName' =&gt; 'product_code', 'KeyType' =&gt; 'HASH'],
                      ['AttributeName' =&gt; 'created_at', 'KeyType' =&gt; 'RANGE']
                  ],
                  'Projection' =&gt; [
                      'ProjectionType' =&gt; 'KEYS_ONLY',
                  ],
              ]                
          ],
          'GlobalSecondaryIndexes' =&gt; [
              [
                  'IndexName' =&gt; 'TokenIndex',
                  'KeySchema' =&gt; [
                      [ 'AttributeName' =&gt; 'token', 'KeyType' =&gt; 'HASH' ]
                  ],
                  'Projection' =&gt; [
                      'ProjectionType' =&gt; 'ALL'
                  ],
                  'ProvisionedThroughput' =&gt; [
                      'ReadCapacityUnits' =&gt; 1, 'WriteCapacityUnits' =&gt; 1 
                  ] 
              ] 
          ],            
          'ProvisionedThroughput' =&gt; [
              'ReadCapacityUnits'    =&gt; 5,
              'WriteCapacityUnits' =&gt; 6
          ]
      ]);
  </code></pre>
  
  <p>When I try to update the attribute "complete" using the query below:</p>
  
  <pre><code>    $this-&gt;dynamoDb-&gt;updateItem([
          'TableName' =&gt; $this-&gt;table,
          'TableIndex' =&gt; 'TokenIndex',
          'Key'   =&gt;  [
              'token'    =&gt;  ['S' =&gt; (string)$this-&gt;token['S']]
          ],
          'UpdateExpression'  =&gt;  'set complete = :complete',
          'ExpressionAttributeValues' =&gt;  [
              ':complete' =&gt;  ['N'   =&gt; (string)1]
          ]
      ]);
  </code></pre>
  
  <p>But I keep getting the following error:</p>
  
  <pre><code>    "The provided key element does not match the schema"
  </code></pre>
  
  <p>Can anybody please advise a newbie. Many thanks.</p>