For a paginated response from Dynamo, I am attempting to preserve the ExclusiveStartKey value. In the code sample, if I use the response.LastEvaluatedKey value directly, subsequent requests work fine.
However, if I serialize the response.LastEvaluatedKey and then serialize it back to be used as the ExclusiveStartKey value, subsequent requests fail with the following error message:
The provided starting key is invalid: One or more parameter values were invalid: Null attribute value types must have the value of true
The deserialized dictionary appears to have the same values as the original dictionary...is there anything to check to see what is different between the two?
QueryResponse response = null;
do
{
string gsiPartitionKey = "gsi-pk-value-1";
var queryRequest = new QueryRequest()
{
TableName = "my-table",
IndexName = "my-index",
KeyConditionExpression = "IndexPk = :s_gsiPartitionKey",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>
{
{
":s_gsiPartitionKey", new AttributeValue { S = gsiPartitionKey}
}
},
Limit = 1
};
if (response != null)
{
//OPTION 1 - OK - Using LastEvaluatedKey directly works fine
//queryRequest.ExclusiveStartKey = response.LastEvaluatedKey;
//OPTION 2 - BAD - Serializing and deserializing fails
var serialized = JsonConvert.SerializeObject(response.LastEvaluatedKey);
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, AttributeValue>>(serialized);
queryRequest.ExclusiveStartKey = deserialized;
}
response = await DynamoDbClient.QueryAsync(queryRequest);
} while (response.LastEvaluatedKey.Count != 0);