'Put or Get from a DynamoDB from a Lambda using Nodejs
I've come across an issue I'm having with being able to do anything with a DynamoDB if my put or get call is in a file outside of my index.js file. For example, my code structure is in an MVC type framework. Below I have my exports.handler in my index.js, which calls a function in a controllers folder. It starts the call, but when it gets to the put or get for dynamo, it goes blank (console logging). No errors, just stops. Has anyone run into this? Example below.
index.js
const locController = require('./controllers/locationsController');
exports.handler = async(event, context) => {
const routeType ='locations';
const GAID = '1234';
switch(routeType) {
case "locations":
response = await locController.getLocations(GAID);
break;
}
/controllers/locationController.js
'use strict';
const AWS = require('aws-sdk');
const documentClient = new AWS.DynamoDB.DocumentClient();
async function getLocations(event, context, callback) {
var params = {
Item : {
"ProfileID": 1234,
"AppID": 1
},
TableName: "Locations"
};
await documentClient.put(params).promise();
}
module.exports = {getLocations};
If I add console.log inside of the function, it shows that I am getting into the function, it just it's writing to the table. The same function by itself put inside of the index.js, works just fine.
Any ideas?
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
