我正在开发无服务器Web应用程序(node.js),遇到了一个困扰我2天的问题。
场景: -用户来到该网站,将图像直接上传到我们的S3存储桶。 -事件被触发并被添加到AWS SQS队列中以供Lambda接收 -Lambda拿起图像钥匙 -然后Lambda(通过SDK)连接到Cloudinary -Lambda然后尝试通过SDK命令cloudinary.v2.uploader.upload('s3:// bucket-name / file-name',(error,result)=> {console.log(error,result)})上传;
问题: 什么都没有上载到Cloudinary,在Cloudwatch中没有发现错误,console.log在回调中为空。
S3存储桶已列入白名单,我已经在我的S3中创建了一个文件.wellknown / cloudinary / cloud_name
index.js
import imageTransform from "./imageTransform";
exports.imageFromQueue = async event => {
event.Records.forEach(async record => {
const body = JSON.parse(record.body).Records[0];
const { eventName, s3 } = body;
if (eventName === "ObjectCreated:Post") {
const { key } = s3.object;
console.log("here", key); --> This gets printed out
const data = await ImageTransform(key);
}
});
};
}
imageTransform.js
const cloudinary = require("cloudinary").v2;
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET
});
const ImageTransform = async imagePath => {
try {
const data = await cloudinary.uploader.upload(
`s3://${process.env.IMAGE_BUCKET}/${imagePath}`
);
console.log(data);
} catch (error) {
console.log("cloudinary - major error", error);
return { majorError: error };
}
}