When trying to place a new entry to the table it misses the execution of the put function. Fuuny, it used to work, and now for whichever reasons it doesn't. allValues is an array, and returns the data fully. Whenever trying to call saveData it does execute everything apart put function.
For some reason, I have tried it a few times, and it worked fine, but suddenly it doesn't place the entry anymore. Tried to play around, but can't seem to find an issue? Might be caused by asynchronous?
//Amazon sdk
let AWS = require("aws-sdk");
let db = require('database');
//Amazon config
AWS.config.update({
region: "us-east-1",
endpoint: "https://dynamodb.us-east-1.amazonaws.com"
});
//DynamoDb client
var docClient = new AWS.DynamoDB.DocumentClient();
//Axios will handle HTTP requests to web service
let axios = require ('axios');
//The ID of the student's data that I will download
let requestID= '*********';
//URL where student data is available
let url = '*************************';
exports.handler = async (event) => {
//Get synthetic data
let allValues = (await axios.get(url + requestID)).data.target;
let allStart = (await axios.get(url + requestID)).data.start;
for(let i = 0; i < allValues.length; i++){
//db.saveData(i, allValues[i], allStart);
}
db.saveData();
};
and my database.js
et AWS = require("aws-sdk");
//Create new DocumentClient
let documentClient = new AWS.DynamoDB.DocumentClient();
//Returns all of the connection IDs
//module.exports.saveData = async (sId, sValue, sTime) => {
module.exports.saveData = async () => {
let params = {
TableName: "SynData",
Item:{
"synId": 66,
"synValue": 1579.21,
"synTime": "2019-01-01"
}
};
//return documentClient.put(params).promise();
documentClient.put(params, function(err, data) {
if (err) {
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Added item:", JSON.stringify(data, null, 2));
}
});
};
The logs do not show any return for put function.