mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
AWS plugin: Add support for a compressed payload
AWS imposes a limit of 16MB in my testing for the payload of a lambda. Compressing it enables us to pass x2-3 more data, thanks to the inefficiencies of JSON
This commit is contained in:
parent
a75434a347
commit
d6a0b06f02
@ -39,6 +39,17 @@ The Lambda boot code looks for an array of tiddlers to load in `event.tiddlers`,
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The event data can optionally be compressed by passing a JSON object with a single property `compressed` that contains a base64 encoded GZIP compressed representation of the JSON payload data. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
var strPayload = JSON.stringify(payload);
|
||||||
|
require("zlib").gzip(strPayload,function(err,buff) {
|
||||||
|
var compressedPayload = {compressed: new Buffer(buff).toString("base64")};
|
||||||
|
// Invoke lambda with compressed payload
|
||||||
|
...
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
! Return data
|
! Return data
|
||||||
|
|
||||||
If the Lambda function successfully executes it returns an object with the following fields:
|
If the Lambda function successfully executes it returns an object with the following fields:
|
||||||
|
@ -16,15 +16,29 @@ exports.handler = function(event,context,callback) {
|
|||||||
$tw.packageInfo = lambdaPackageInfo;
|
$tw.packageInfo = lambdaPackageInfo;
|
||||||
// Load any tiddlers from the package
|
// Load any tiddlers from the package
|
||||||
$tw.preloadTiddlerArray(lambdaTiddlers);
|
$tw.preloadTiddlerArray(lambdaTiddlers);
|
||||||
// Load any tiddlers from the event
|
// Decompress the event data if required
|
||||||
if(event.tiddlers) {
|
if(typeof event.compressed === "string") {
|
||||||
$tw.preloadTiddlerArray(event.tiddlers);
|
require("zlib").gunzip(Buffer.from(event.compressed,"base64"),function(err,buff) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
boot(JSON.parse(buff.toString()));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
boot(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
function boot(event) {
|
||||||
|
// Load any tiddlers from the event
|
||||||
|
if(event.tiddlers) {
|
||||||
|
$tw.preloadTiddlerArray(event.tiddlers);
|
||||||
|
}
|
||||||
|
// Load the commands from the event
|
||||||
|
$tw.boot.argv = (event.commands || []).slice(0);
|
||||||
|
// Boot the TW5 app
|
||||||
|
_boot($tw);
|
||||||
|
$tw.boot.boot(function() {
|
||||||
|
callback(null,$tw["lambda-result"]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// Load the commands from the event
|
|
||||||
$tw.boot.argv = (event.commands || []).slice(0);
|
|
||||||
// Boot the TW5 app
|
|
||||||
_boot($tw);
|
|
||||||
$tw.boot.boot(function() {
|
|
||||||
callback(null,$tw["lambda-result"]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user