2015-06-18 20 views
15

Lambda में S3 में ऑब्जेक्ट अपलोड करने के लिए प्रतीत नहीं होता है। सब कुछ स्थानीय रूप से ठीक काम करता है। लॉग में कोई त्रुटि नहीं पता चलता है कि क्या गलत हो रहा है ...Lambda में S3 में ऑब्जेक्ट को कैसे अपलोड करें?

नीचे कोड:

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); // an error occurred 
     else console.log(data);   // successful response 
    }); 
    console.log('done'); 
    context.done(); 
}; 

रन सफलतापूर्वक w/ओ त्रुटि है, लेकिन s3.upload में कॉलबैक के नाम से जाना प्रतीत नहीं होता। बाल्टी में कोई वस्तु नहीं बनाई गई है।

सत्यापित आईएएम भूमिका अनुमतियां पूर्ण पहुंच प्रदान करने, साथ ही साथ स्थानीय रूप से परीक्षण करके कोई समस्या नहीं थीं।

आउटपुट

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 
+0

एस 3 ऑब्जेक्ट दूसरी बार क्यों बनाया गया है? (स्थानीय और वैश्विक स्तर पर) –

+0

मेरे पास एक पूर्ण कार्य संस्करण है जो यहां समझाया गया है: http://stackoverflow.com/questions/33631229/how-to-set-open-download-permissions-on-a-file-created-in -s3-with-amazon-lambda/33632736 –

उत्तर

41

मुझे लगता है आप s3.upload() से पहले context.done() समारोह बुला रहे हैं वापस जाने के लिए एक मौका है। यदि आप अपलोड प्रतिक्रिया कोड ब्लॉक में context.done() स्थानांतरित करते हैं, तो इसे काम करना चाहिए।

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); // an error occurred 
     else console.log(data);   // successful response 

     console.log('actually done!'); 
     context.done(); 
    }); 

    console.log('done?'); 
    //context.done(); 
}; 
+2

धन्यवाद @ जेम्स, यह मेरे लिए काम करता है :-) –

+1

@ कैथरीन ओसबोर्न यदि यह काम करता है, तो कृपया उत्तर स्वीकार करें। यह समुदाय में दूसरों की मदद करता है। –

+0

@ParthapratimNeog मैं चाहता था लेकिन मैंने सवाल नहीं पूछा ;-) –

संबंधित मुद्दे