Interact with Amazon Lambda
In your Amazon S3 account, set up a Node.js-based Lambda function that forwards incoming messages to a listening session.
'use strict';
let https = require('https');
exports.handler = (event, context, callback) => {
var req = https.request({
host: 'channelbroker.wolframcloud.com',
path: '/users/user@sample.com/cloud?operation=send',
method: 'POST',
}, function(res) {
console.log('status:', res.statusCode);
});
req.on('error', function(e) {
console.error(e);
});
req.write(JSON.stringify(event));
req.end();
};
Start listening on a channel that reads images from a bucket with appropriate permissions.
In[1]:=
bucket = "wl-channels";
In[2]:=
image = "";
In[3]:=
listener =
ChannelListen[
"cloud", (image =
ImportString[
URLRead["https://" <> bucket <>
".s3.amazonaws.com/" <> #Message["Records"][[1]]["s3"][
"object"]["key"], "Body"]]) &,
Permissions -> <|"All" -> "Write", "Owner" -> {"Read", "Execute"}|>]
Out[3]=
Upload a few images to your bucket and show them dynamically as soon as they arrive.
In[4]:=
Dynamic[image]
Out[4]=
The accumulated log of received messages.
In[5]:=
listener["Dataset"]
Out[5]=