I have a NodeJS function in Lambda which calls out to a library in order to run a geospatial query in Dynamo DB.
Ultimately, I would like the results from this query to be returned by Lambda, as this Lambda function will ultimately be invoked by another and as such the results must be returned.
I am unable to return the results of the promise in a Lambda function.
I've tried rewriting the code several times, understanding promises, using async await... I've read a number of articles including https://dashbird.io/blog/aws-lambda-supports-node-version-8.10/ https://techsparx.com/software-development/aws/aws-sdk-promises.html https://medium.com/tensult/async-await-on-aws-lambda-function-for-nodejs-2783febbccd9 Getting API call in node8.10 in Lambda results in Promise <pending> and undefined
To no avail.
const AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB();
const ddbGeo = require('dynamodb-geo');
const config = new ddbGeo.GeoDataManagerConfiguration(ddb, 'MyGeoTable');
const myGeoTableManager = new ddbGeo.GeoDataManager(config);
exports.handler = async function (event, context) {
let data = await myGeoTableManager.queryRadius({
RadiusInMeter: 1000,
CenterPoint: {latitude: 51.50, longitude: -0.17}
});
console.log(data);
return data;
}
The code runs, but Lambda returns [] as the result.