javascript - How to upload an object into S3 in Lambda? -


can't seem upload object s3 in lambda. works fine locally. no errors in logs show what's going wrong...

code below:

console.log('loading function'); var aws = require('aws-sdk'); var s3 = new aws.s3();  exports.handler = function(event, context) {     //console.log(json.stringify(event, null, 2));     var s3 = new aws.s3();     var param = {bucket: 'flow-logs', key: 'test-lambda-x', body: 'me me me'};     console.log("s3");     s3.upload(param, function(err, data) {         if (err) console.log(err, err.stack); // error occurred         else console.log(data);           // successful response     });     console.log('done');     context.done(); }; 

runs w/o error, callback in s3.upload doesn't seem called. no object in bucket created.

verified iam role permissions weren't problem granting full access, testing out locally.

output

start requestid: d4847fdb-160c-11e5-8a8c-b555b123e14d 2015-06-18t22:53:29.750z    d4847fdb-160c-11e5-8a8c-b555b123e14d    s3 2015-06-18t22:53:30.271z    d4847fdb-160c-11e5-8a8c-b555b123e14d    done end requestid: d4847fdb-160c-11e5-8a8c-b555b123e14d 

i suspect calling context.done() function before s3.upload() has chance return. if move context.done() upload response code block, should work.

var aws = require('aws-sdk'); var s3 = new aws.s3();  exports.handler = function(event, context) {     //console.log(json.stringify(event, null, 2));     var s3 = new aws.s3();     var param = {bucket: 'flow-logs', key: 'test-lambda-x', body: 'me me me'};     console.log("s3");     s3.upload(param, function(err, data) {         if (err) console.log(err, err.stack); // error occurred         else console.log(data);           // successful response          console.log('actually done!');         context.done();     });      console.log('done?');     //context.done(); }; 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -