[英]AWS Lambda function to updload json to s3 bucket not working
When I run this function, it says that it succeeds, but the file is not in the s3 bucket. 当我运行此函数时,它说成功了,但是文件不在s3存储桶中。
var AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
AWS.config.update({
region: 'us-west-2',
accessKeyId: 'xxx',
secretAccessKey: 'xxx'
});
var s3 = new AWS.S3();
s3.putObject({
Bucket: 'mybucket',
Key: 'test.json',
Body: [{test: 'test'}, {test: 'test'}],
ContentType: "application/json"
}, function(){});
context.succeed('SUCCESS');
};
NodeJs is a interesting language. NodeJs是一种有趣的语言。
Most languages would process your code like this 大多数语言都会像这样处理您的代码
Node js will process in this order. Node js将按此顺序处理。
var AWS = require('aws-sdk'); exports.handler = (event, context, callback) => { AWS.config.update({ region: 'us-west-2', accessKeyId: 'xxx', secretAccessKey: 'xxx' }); var s3 = new AWS.S3(); s3.putObject( { Bucket: 'mybucket', Key: 'test.json', Body: [{test: 'test'}, {test: 'test'}], ContentType: "application/json" }, function(err, res){ if(err){ console.log(err); } callback(err, "processed"); }); };
^The callback will tell lambda that it is the end of the script. ^该回调将告诉lambda它是脚本的结尾。 It will now process like this.
现在将按以下方式处理。
您可以使用Q https://www.npmjs.com/package/q或NodeJs promises以要求的顺序处理任务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.