Wolfram Language

Channel Framework

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
bucket = "wl-channels";
In[2]:=
Click for copyable input
image = "";
In[3]:=
Click for copyable input
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]:=
Click for copyable input
Dynamic[image]
Out[4]=

The accumulated log of received messages.

In[5]:=
Click for copyable input
listener["Dataset"]
Out[5]=

Related Examples

de es fr ja ko pt-br ru zh