DynamoDB : Pagination with "withExclusiveStartKey" on a Global Secondary Index
<p>I have DynamoDB table called "product" with a Global Secondary Index on "userId".Primary Key is on "id".
I am trying to implement Querying with pagination using "withExclusiveStartKey"  on "userID" GSI.
However, I get following exception when I pass a valid lastId:</p>

<blockquote>
  <p><em>Exclusive Start Key must have same size as table's key schema
  (Service: AmazonDynamoDBv2; Status Code: 400; Error Code:
  ValidationException; Request ID:
  822db97e-04a3-4c36-8c72-6008e2693679)</em></p>
</blockquote>

<p>What am I doing wrong here ?</p>

<pre><code>public QueryResultPage&lt;Product&gt;  findPaged(String userId,int limit,String lastId) {
        DynamoDBMapper mapper = new DynamoDBMapper(dynamoDb);       
        Map&lt;String, AttributeValue&gt; vals = new HashMap&lt;&gt;();
        vals.put(":valUserId", new AttributeValue().withS(userId));
                DynamoDBQueryExpression&lt;Product&gt; queryExp = new         DynamoDBQueryExpression&lt;Product&gt;()
                .withKeyConditionExpression("userId = :valUserId")
                .withIndexName(ModelConsts.TBL_PRODUCT_GSI_USERID)
                .withExpressionAttributeValues(vals)
                .withScanIndexForward(false)
                .withConsistentRead(false)
                .withLimit(limit);  
           if (lastId != null) {//paging
            Map&lt;String, AttributeValue&gt; exclusiveStartKey = new HashMap&lt;String, AttributeValue&gt;();
                    exclusiveStartKey.put("id", new AttributeValue().withS(lastId));
               queryExp = queryExp.withExclusiveStartKey(exclusiveStartKey);
        }   
        QueryResultPage&lt;Product&gt; result = mapper.queryPage(Product.class, queryExp);
        return result;      
    }
</code></pre>