Hi there, (First of all, sorry for my English XD)
I’m newbie trying get my first records from dynamodb (local).
I don’t know why I can get the records, but I can’t send by the return.
Here’s a fragment of my code. Any comments are welcome.
module.exports.temperature = async(event,context)=>{
console.log(‘[INFO] Get temperature from local DynamoDB’);if(IS_OFFLINE===‘true’){
console.log(‘[INFO] Definition of variables’);
var dynamodb = require(‘serverless-dynamodb-client’);
var rawClient = dynamodb.raw;
var params = {Key: {“id”: {N: “123”},“e”: {N: “1234”}}, TableName: “weather-station-dev”};
var Item;
console.log(‘[INFO] End definition of variables’);
console.log(‘[INFO] Get data from dynamoDB-local’);
await rawClient.getItem(params, function(err, data) {
if(err) console.log(‘[ERROR]’,err, err.stack);
else {
console.log(‘[INFO] Get data ====>’,data);
Item = data;
console.log(‘[INFO] Get Item ====>’,Item);
}
});
console.log(‘[INFO] Last line before return’);
return {
statusCode: 200,
body: JSON.stringify(
{
“Item”: Item
})
};
}else{
return {
statusCode: 200,
body: JSON.stringify(
{
message: ‘From AWS’
})
};
}
}
And for the console, I get this
offline: GET /dev/temperature (λ: temperature)
[INFO] Get temperature from local DynamoDB
[INFO] Definition of variables
[INFO] End definition of variables
[INFO] Get data from dynamoDB-local
[INFO] Last line before return
offline: (λ: temperature) RequestId: ckhuwtsku0005rqx7d6mx4mad Duration: 75.84 ms Billed Duration: 100 ms
[INFO] Get data ====> { Item: { e: { N: ‘1234’ }, id: { N: ‘123’ } } }
[INFO] Get Item ====> { Item: { e: { N: ‘1234’ }, id: { N: ‘123’ } } }
I can get the information from de dynamoDB (local), but I can’t send to the page.
Thanks in advance.
Regards
AJM