The following is node.js query in AWS lambda on a dynamoDB JSON object. UserID is the primary key with no sort key. GeoHash is a secondary key, with index name "GeoHash-index". The call succeeds with no error, but does not result in anything being returned. It's possible that the test data below is wrong as it does not offer any connection to the index name, but I'm new to AWS/noSQL and a little lost.
var AWS = require('aws-sdk');
var docClient = new AWS.DynamoDB({apiVersion: '2012-08-10'});
exports.handler = function(event,context,callback) {
console.log(JSON.stringify(event, null, ' '));
var tableName = "table1";
// getItem
docClient.getItem({
TableName: tableName,
IndexName: "GeoHash-index",
KeyConditionExpression: "GeoHash = :geohash",
ExpressionAttributeValues: {":geohash": "dpz886gb0tb0"}
}),
function(err,data){
if(err){
callback(err);
} else {
callback(null,data);
}
}
};
Where the lambda test data is
{
"GeoHash": "dpz886gb0tb0",
"Radius": 2,
"Timestamp": 1472601493180,
"UserID": "User1"
}
The GeoHash string should match each other. Thoughts?
EDIT No success with this method either
var AWS = require('aws-sdk');
var docClient = new AWS.DynamoDB({apiVersion: '2012-08-10'});
exports.handler = function index(event, context, callback) {
var params = {
TableName: "LocationAware1",
IndexName: "GeoHash-index",
KeyConditionExpression: "GeoHash = :geohash",
ExpressionAttributeValues: {
":geohash": {'S': 'dpz886gb0tb0'}
},
};
docClient.query(params, function(err, data) {
if (err)
console.log(JSON.stringify(err));
else
console.log(JSON.stringify(data));
});
}