1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

AWS Plugin: Lambda should return list of files written to S3

This commit is contained in:
Jermolene 2017-08-29 21:41:50 +01:00
parent 06ea4060cb
commit 08ae7321c1
3 changed files with 17 additions and 3 deletions

View File

@ -38,3 +38,9 @@ The Lambda boot code looks for an array of tiddlers to load in `event.tiddlers`,
}
```
! Return data
If the Lambda function successfully executes it returns an object with the following fields:
* ''lambda-result'': An array of `{bucketname,key}` pairs for each file written to S3 within the lambda function

View File

@ -20,7 +20,7 @@ title:
callback: invoked with (err,{body:,type:}
*/
function getFile(region,bucketName,title,callback) {
console.log("Reading file from S3",bucketName,title)
console.log("Reading file from S3",bucketName,title);
var AWS = require("aws-sdk"),
s3bucket = new AWS.S3({
region: region
@ -46,7 +46,11 @@ console.log("Reading file from S3",bucketName,title)
Put a file to an S3 bucket
*/
function putFile(region,bucketName,title,text,type,callback) {
console.log("Writing file to S3",bucketName,title,type)
// Log the write
if($tw["lambda-result"]) {
$tw["lambda-result"]["files-written"].push({bucket: bucketName,key: title});
}
console.log("Writing file to S3",bucketName,title,type);
var AWS = require("aws-sdk"),
s3bucket = new AWS.S3({
region: region

View File

@ -8,6 +8,10 @@ TiddlyWiki for AWS
exports.handler = function(event,context,callback) {
// Initialise the boot prefix
global.$tw = _bootprefix();
// Initialise the returned results
$tw["lambda-result"] = {
"files-written": []
};
// Some default package info
$tw.packageInfo = lambdaPackageInfo;
// Load any tiddlers from the package
@ -21,6 +25,6 @@ exports.handler = function(event,context,callback) {
// Boot the TW5 app
_boot($tw);
$tw.boot.boot(function() {
callback(null,"TiddlyWiki execution successful");
callback(null,$tw["lambda-result"]);
});
}