Node.js- 扫描 DynamoDB AWS- 添加参数
Node.js- scan DynamoDB AWS- adding parameters
我使用 Lambda AWS 从 dynamoDB 获取数据。我尝试将参数添加到我从 android app:
发送到 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};
我使用 Lambda AWS 从 dynamoDB 获取数据。我尝试将参数添加到我从 android app:
发送到 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};