When I run this function, it says that it succeeds, but the file is not in the s3 bucket.
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.
Most languages would process your code like this
Node js will process in this order.
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. It will now process like this.
您可以使用Q https://www.npmjs.com/package/q或NodeJs promises以要求的顺序处理任务。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.