我是Lambda和S3存储桶的新手,所以请多多包涵。
我已经设置了一个AWS SES,它可以将电子邮件发送到S3存储桶,效果很好。我现在想做的是,当S3存储桶收到一个新对象时触发了事件ObjectCreated
,而我触发了一个Lambda
到URL的POST
函数(node.js)在服务器上获取文件名,然后文件名将允许我下载该特定对象并处理电子邮件。
这是细分
ObjectCreated
事件中触发了Lambda函数(node.js)POST
发送到服务器上的脚本,并向我发送文件名问题在于POST
从未发生。对我有帮助吗?
我要避免的是创建一个cron作业,该作业每分钟检查一次我的存储桶,以查看是否有新的电子邮件(对象)并以这种方式处理它们。每当有新对象进入存储桶时,我想做的就是触发脚本并发送对象名称,这样我就可以立即抓住该特定对象并立即对其进行处理。
SES规则
Lambda
exports.handler = (event, context, callback) => {
var https = require('https');
var data = JSON.stringify({
'fileName': event.Records[0].s3.object.key,
});
var options = {
host: 'example.com',
port: '80',
path: '/path/script/this_script.php',
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': data.length
}
};
var req = https.request(options, function(res) {
var msg = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
msg += chunk;
});
res.on('end', function() {
console.log(JSON.parse(msg));
context.succeed();
});
});
req.write(data);
req.end();
};
无论我测试Lambda时做什么,我总是会收到此错误
{
"errorType": "TypeError",
"errorMessage": "Cannot read property '0' of undefined",
"trace": [
"TypeError: Cannot read property '0' of undefined",
" at Runtime.exports.handler (/var/task/index.js:5:34)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}