Dynamodb: Querying tables with secondary index
You are not querying the secondary index, you are querying the primary index(hash and range key).To use a secondary index with DynamoDB you must use V2 of the API and specify the index in the query operation
client = AWS::DynamoDB::Client.new(api_version: '2012-08-10') client.query( { :table_name: 'table', :index_name: "timestamp-index", :select: 'ALL_PROJECTED_ATTRIBUTES', :key_conditions: { 'hk' => { :comparison_operator: 'EQ', :attribute_value_list: [ {'s' => 'aaaa'} ] }, 'timestamp' => { :comparison_operator: 'GE', :attribute_value_list: [ {'s' => Time.now.utc.iso8601} ] } } })
You can use "scan" instead "query"http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#scan-property
I can emphatize that scan in slower than query, scan is not recomended for huge amount data retrieve.
I did this with the next schema
DB SchemaWherePrimary partition key id (String)
//JavaScript EXAMPLE-1 var params = { TableName : 'users', FilterExpression : 'isActive = :isActive', ExpressionAttributeValues : {':isActive' : true} }; dynamoDBClient.scan(params, function(err, data){ if(err){ return console.error(err); } console.log(data.Items); });
I hope help you.
Regards.