Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

I have some certificate files over s3 (public) and I am to download and use these files in my code, If I write equivalent code in nodejs at my local, it just runs fine, but in AWS lambda it just crashes.

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("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) {


  console.log("downloaded the certificate");

  var keyfile = fs.createWriteStream(keyFileName);

  var keyrequest = https.get(keyPath, function(keyresponse) {


    console.log("downloaded the key file");


  var options = { 




                      "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( / 1000) + 3600; // Expires 1 hour from now.        

  note.payload = {'COMMAND': content};       

  apnConnection.pushNotification(note, myDevice);

  console.log('message sent to ' + apnId);       





The error I get is related to accessing files I suppose -


 throw er; // Unhandled 'error' event 


Error: EACCES, open 'PushChatCert.pem'

So while on AWS Lambda is there some specific concerns when one is downloading a file and using it, related to its path or something, where do the files stay when they get downloaded, in fact, I don't even see the log of file getting downloaded.

1 Answer

0 votes
by (44.4k points)

In Lambda, you can only write in the available local file system which contains a temporary directory /tmp. So, whatever you are writing, make sure you write it in the /tmp directory.

You should also read AWS Lambda to get an overview of this concept.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories