【发布时间】:2019-07-27 11:40:27
【问题描述】:
我一直在使用下面的代码(我现在添加了等待)将文件发送到 S3。它在我的 lambda 代码上运行良好,但当我转移到 MP4 等较大的文件时,我觉得我需要 async/await。
如何将其完全转换为 async/await?
exports.handler = async (event, context, callback) => {
...
// Copy data to a variable to enable write to S3 Bucket
var result = response.audioContent;
console.log('Result contents ', result);
// Set S3 bucket details and put MP3 file into S3 bucket from tmp
var s3 = new AWS.S3();
await var params = {
Bucket: 'bucketname',
Key: filename + ".txt",
ACL: 'public-read',
Body: result
};
await s3.putObject(params, function (err, result) {
if (err) console.log('TXT file not sent to S3 - FAILED'); // an error occurred
else console.log('TXT file sent to S3 - SUCCESS'); // successful response
context.succeed('TXT file has been sent to S3');
});
【问题讨论】:
-
你不需要使用
await var params = ...await只对promise有用
标签: javascript node.js amazon-s3 async-await aws-lambda