Node.js-扫描DynamoDB AWS-添加参数
我使用Lambda AWS从dynamoDB获取数据。 我尝试添加参数,我从Android应用程序发送到Lambda的参数:
if (typeof event.high_lat != "undefined") { params.ExpressionAttributeValues = event.high_lat; }
但是我得到一个错误:
[InvalidParameterType: Expected params.ExpressionAttributeValues to be a map] message: 'Expected params.ExpressionAttributeValues to be a map',
任何人都知道如何解决它?
我的整个代码:
var AWS = require('aws-sdk'); var db = new AWS.DynamoDB(); exports.handler = function(event, context) { var params = { TableName: "Events", //"StreamsLambdaTable", ProjectionExpression: "ID, description, endDate, imagePath, locationLat, locationLon, #nm, startDate, #tp, userLimit", //specifies the attributes you want in the scan result. FilterExpression: "locationLon between :lower_lon and :higher_lon and locationLat between :lower_lat and :higher_lat", ExpressionAttributeNames: { "#nm": "name", "#tp": "type", }, ExclusiveStartKey: { "ID": {"S": event.LastEvaluatedKey} }, ExpressionAttributeValues: { ":lower_lon": {"N": event.low_lon}, ":higher_lon": {"N": event.high_lon}, ":lower_lat": {"N": event.low_lat} } }; if (typeof event.high_lat != "undefined") { params.ExpressionAttributeValues = event.high_lat; } db.scan(params, function(err, data) { if (err) { console.log(err); // an error occurred } else { data.Items.forEach(function(record) { console.log( record.name.S + ""); }); context.succeed(data.Items); } }); };
从android应用程序发送的代码示例:
{ "low_lon": "16", "high_lon": "17", "low_lat": "52", "high_lat": "53" }
您正在使用单个值吹掉您的整个ExpressionAttributeValues贴图。 你只需要看看你上面写的代码,看看你应该如何将值添加到ExpressionAttributeValues映射。
改变这个:
params.ExpressionAttributeValues = event.high_lat;
对此:
params.ExpressionAttributeValues[":higher_lat"] = {"N": event.high_lat};