我的Lambda函数中有此代码
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
exports.handler = (event, context, callback) => {
const bucketName = "dhaval-upload";
let data = {
firstname: event.firstname,
lastname: event.lastname,
email: event.email,
userAgent: event.userBrowser,
userIP: event.userIP
};
let params = {
Body: JSON.stringify(data),
Bucket: bucketName,
Key: event.email
};
s3.putObject(params);
callback(null, { message: event.email});
};
这将返回成功回调,但不会在s3中写入对象。
这是可行的,但由于某种原因现在却没有。
请注意:-我检查了cloudwatch日志,但从中找不到问题的原因。
答案 0 :(得分:0)
也许您可以这样尝试,应该对代码使用回调/异步
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
exports.handler = (event, context, callback) => {
const bucketName = "dhaval-upload";
let data = {
firstname: event.firstname,
lastname: event.lastname,
email: event.email,
userAgent: event.userBrowser,
userIP: event.userIP
};
let params = {
Body: JSON.stringify(data),
Bucket: bucketName,
Key: event.email
};
// s3.putObject(params);
// callback(null, { message: event.email});
// === it works like this ===
s3.putObject(params, (err, data) => {
if (err) callback(null, err);
else callback(null, { message: event.email });
});
};