与亚马逊 Lambda 的互动
在亚马逊 S3 账户中设置一个基于 Node.js 的 Lambda 函数,其向侦听会话转发接收的消息.
'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();
};
开始侦听读取有适合权限的存储器中图像的通道.
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]=
上传少量图像到你的存储器,并在收到的同时立即进行动态显示.
In[4]:=
Dynamic[image]
Out[4]=
接收到的消息的累积日志.
In[5]:=
listener["Dataset"]
Out[5]=