I'm getting this error from lambda: errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Unable to stringify response body
I'm trying to trigger my lambda from an upload in s3 (this part is working) and then that should post something into dynamoDB
here is my lambda in full
var AWS = require('aws-sdk');
var S3 = require('aws-sdk/clients/s3');
const s3 = new AWS.S3()
var DynamoDB = new AWS.DynamoDB.DocumentClient();
exports.handler = async (event) => {
// TODO implement
var bucket = event['Records'][0]['s3']['bucket']['name']
var json_file_name = event['Records'][0]['s3']['object']['key']
var params = {
Bucket: bucket,
Key: json_file_name
};
const data = await s3.getObject(params).promise();
const dataToDb = data.Body.toString('utf-8');
console.log(dataToDb, 'TESTING ====')
var dbparams = {
TableName: "MY-TABLE-NAME",
Item: dataToDb,
};
const putIntoDB = await DynamoDB.put(dbparams, function (err) {
if (err) {
console.log(err, 'er===');
}
else {
console.log(dbparams, 'db====')
}
});
return putIntoDB
};
the data that is coming from s3 is just a simple json object with 4 keys so nothing big at all.
my table consists of just a primary key called user_id and that field IS in my json object that comes back from S3 so no idea why this isn't working?