2015-08-11 17 views
12

Tôi có một số tệp chứng chỉ trên s3 (công khai) và tôi tải xuống và sử dụng các tệp này trong mã của mình, Nếu tôi viết mã tương đương trong nútj tại địa phương của tôi, nó chỉ chạy tốt, nhưng trong AWS lambda nó chỉ bị treo.AWS Lambda - tải xuống một tệp và sử dụng cùng chức năng - nodejs

var apn = require('apn'); 
var https = require('https'); 
var fs = require('fs'); 

exports.handler = function(event, context) { 
    console.log("Running aws apn push message function"); 
    console.log("=================================="); 
    console.log("event", event); 

    var certPath = event.certPath; 
    var keyPath = event.keyPath; 
    var certFileName = event.certFileName; 
    var keyFileName = event.keyFileName; 
    var passphrase = event.passphrase; 
    var apnId = event.apnId; 
    var content = event.content; 


var certfile = fs.createWriteStream(certFileName); 
var certrequest = https.get(certPath, function(certresponse) { 
    certresponse.pipe(certfile); 
    console.log("downloaded the certificate"); 

    var keyfile = fs.createWriteStream(keyFileName); 
    var keyrequest = https.get(keyPath, function(keyresponse) { 
    keyresponse.pipe(keyfile); 
    console.log("downloaded the key file"); 


    var options = { 
         "cert":certFileName, 
         "key":keyFileName, 
         "passphrase":passphrase, 
         "batchFeedback": true, 
         "interval": 10 
         }; 

    var apnConnection = new apn.Connection(options); 

    var myDevice = new apn.Device(apnId); 
    var note = new apn.Notification(); 
    note.expiry = Math.floor(Date.now()/1000) + 3600; // Expires 1 hour from now.   
    note.payload = {'COMMAND': content};  
    apnConnection.pushNotification(note, myDevice); 
    console.log('message sent to ' + apnId);  

    context.done(); 

    }); 
}); 
} 

Lỗi tôi nhận được có liên quan đến việc truy cập file i giả -

events.js:72 
throw er; // Unhandled 'error' event 
^ 
Error: EACCES, open 'PushChatCert.pem' 

Vì vậy, trong khi trên AWS Lambda là có một số mối quan tâm cụ thể khi ai tải một tập tin và sử dụng nó, liên quan đến đường đi của nó hay một cái gì đó, nơi nào các tập tin ở lại khi họ nhận được tải về, trên thực tế tôi thậm chí không nhìn thấy nhật ký của tập tin nhận được tải về.

Trả lời

30

Hệ thống tệp cục bộ duy nhất bạn có thể ghi vào trong Lambda là/tmp để đảm bảo đường dẫn cho tệp cục bộ bạn đang cố gắng ghi vào thư mục/tmp và bạn sẽ được đặt.

Các vấn đề liên quan