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]:=
![Click for copyable input](assets.en/interact-with-amazon-lambda/In_62.png)
bucket = "wl-channels";
In[2]:=
![Click for copyable input](assets.en/interact-with-amazon-lambda/In_63.png)
image = "";
In[3]:=
![Click for copyable input](assets.en/interact-with-amazon-lambda/In_64.png)
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]=
![](assets.en/interact-with-amazon-lambda/O_62.png)
Upload a few images to your bucket and show them dynamically as soon as they arrive.
In[4]:=
![Click for copyable input](assets.en/interact-with-amazon-lambda/In_65.png)
Dynamic[image]
Out[4]=
![](assets.en/interact-with-amazon-lambda/O_63.png)
The accumulated log of received messages.
In[5]:=
![Click for copyable input](assets.en/interact-with-amazon-lambda/In_66.png)
listener["Dataset"]
Out[5]=
![](assets.en/interact-with-amazon-lambda/O_64.png)