Querying a Global Secondary Index in dynamodb Local
As stated above, you need to use the DynamoDB Document Client if you want to abtract away the type casting.
var docClient = new AWS.DynamoDB.DocumentClient();
...then you can just use the above listed object notation to call the API.
{ ':pub_id': '700'}
Ran into this issue myself, I was using DynamoDB() in some places and the docClient in others, couldn't figure it out for awhile, but that'll solve it.
Turns out it depends on whether you use AWS.DynamoDB
or AWS.DynamoDB.DocumentClient
.
Check the difference in the documentation: AWS.DynamoDB.query vs. AWS.DynamoDB.DocumentClient.query
In the DocumentClient the doc clearly states:
The document client simplifies working with items in Amazon DynamoDB by abstracting away the notion of attribute values. This abstraction annotates native JavaScript types supplied as input parameters, as well as converts annotated response data to native JavaScript types.
...
Supply the same parameters as AWS.DynamoDB.query() with AttributeValues substituted by native JavaScript types.
Maybe you where also referring to the DynamoDB API Reference which in fact makes no assumptions about the used SDK but uses plain HTTP Requests in the examples.
Thus using the AWS.DynamoDB.DocumentClient
you would just provide a simple key-value map for ExpressionAttributeValues
as suggested by @gior91.
Try to change ExpressionAttributeValues
from this
{
TableName: 'Configs',
IndexName: 'publisher_index',
KeyConditionExpression: 'publisherId = :pub_id',
ExpressionAttributeValues: { ':pub_id': { S: '700' } }
}
to
{
TableName: 'Configs',
IndexName: 'publisher_index',
KeyConditionExpression: 'publisherId = :pub_id',
ExpressionAttributeValues: { ':pub_id': '700'}
}
From { ':pub_id': { S: '700' } }
to { ':pub_id': '700'}
.
I had the same problem and I spent 2 days for this. The official documentation in misleading.