Ho alcuni file di certificati su s3 (pubblico) e devo scaricare e utilizzare questi file nel mio codice, se scrivo un codice equivalente in nodejs al mio locale funziona semplicemente, ma in lambda AWS si blocca.AWS Lambda - download di un file e utilizzo nella stessa funzione - 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();
});
});
}
errore che ottengo è legato a accedere ai file suppongo -
events.js:72
throw er; // Unhandled 'error' event
^
Error: EACCES, open 'PushChatCert.pem'
Così, mentre su AWS Lambda è lì alcune preoccupazioni specifiche quando si sta scaricando un file e che lo utilizzano, in relazione al suo percorso o qualcosa, dove rimangono i file quando vengono scaricati, in effetti non vedo nemmeno il log del file scaricato.