I've got an Alexa skill named Dominion Helper and I'd like to add the ability to set some user preferences and have them save in the background behind sessions. I'm working in Node.JS My plan has been to put these into JSON and then stringify it into an S3 object. I was under the impression that I was having a permissions error, but I finally had a test object save, I think through brute force and dumb luck. My current thinking is that the Lambda function hits the emit and exits prior to the callback/completion of the s3.putObject attempt.
How can I ensure that execution waits to save the file?
var s3 = new AWS.S3(); var params = { Bucket : bucket, Key : key, Body : JSON.stringify(body), ContentType: "text/plain" }; s3.putObject(params, function(err, data){ var foo = "bar"; if (err) {console.log(err, err.stack); // an error occurred return err; } else {console.log(data); // successful response return data; } });
Thanks in advance.