Я пытаюсь реализовать простую Node Js функцию на AWS Lambda для запроса данных из DynamoDB. Я подключил эту лямбда-функцию к своему API-шлюзу, но я не вижу никаких результатов при доступе к URL-адресу API.
//Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'us-east-1'});
// Create DynamoDB service object
var b = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
ExpressionAttributeNames: {
"#devicetimestamp": "timestamp"
},
ExpressionAttributeValues: {
':unitID': {S: 'arena-MXHGMYzBBP5F6jztnLUdCL'},
':dtimestamp' : {S: '1582920096000'}
},
KeyConditionExpression: 'id = :unitID and #devicetimestamp > :dtimestamp',
TableName: 'IoTdata2'
};
b.query(params, function(err, results) {
if (err) {
console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
} else {
console.log("Query succeeded.");
console.log(JSON.stringify(results));
}
});
Код работает нормально, так как вижу результаты из console.log(JSON.stringify(results));
при использовании события обработчик
//Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'us-east-1'});
// Create DynamoDB service object
var b = new AWS.DynamoDB({apiVersion: '2012-08-10'});
exports.handler = (event, context, callback) => {
var params = {
ExpressionAttributeNames: {
"#devicetimestamp": "timestamp"
},
ExpressionAttributeValues: {
':unitID': {S: 'arena-MXHGMYzBBP5F6jztnLUdCL'},
':dtimestamp' : {S: '1582920096000'}
},
KeyConditionExpression: 'id = :unitID and #devicetimestamp > :dtimestamp',
TableName: 'IoTdata2'
};
b.query(params, function(err, results) {
if (err) {
console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
callback(err);
} else {
console.log("Query succeeded.");
console.log(JSON.stringify(results));
callback(null, results);
}
});
};
```i don't see any response in API URL.I am new to nodeJS, Any suggestions will be greatly appreciated. Thanks