Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access /tmp folder in Lambda with in Node?

I'm trying to save a processed image momentally in /tmp folder but it's not working for me. Assuming it's under the root folder I'm trying to get it this way:

let tempraryImageDirectory: string;
if (process.env.DEV && process.env.DEV === 'Yes') {
  tempraryImageDirectory = path.join(__dirname, `../../tmp/`);
} else {
  tempraryImageDirectory = path.join(__dirname, `./tmp/`);
}

The else choice here is to test locally. I don't want to create a /tmp folder in the root directory. Locally everything is very fine. But in Lambda at the moment any operation happens on the directory CloudWatch never shows any of my logs written after that and my function fails for unknown reason. Any idea if I'm addressing the /tmp folder correctly?

like image 506
Lee Maan Avatar asked Apr 15 '26 10:04

Lee Maan


2 Answers

The directory is just /tmp, it is not relative to the working directory:

let tempraryImageDirectory: string;
if (process.env.DEV && process.env.DEV === 'Yes') {
  tempraryImageDirectory = path.join(__dirname, `../../tmp/`);
} else {
  tempraryImageDirectory = '/tmp/';
}

You may also wish to rename your variable to include the o in temporary if you did not leave it out on purpose.

like image 147
Paul Avatar answered Apr 16 '26 22:04

Paul


Change this: ./tmp/, i.e. "the /tmp directory under the current working directory"

To this: /tmp/, i.e. "the /tmp directory under the root file system"

like image 20
Mark B Avatar answered Apr 17 '26 00:04

Mark B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!