Lee Maan
Lee Maan

Reputation: 719

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?

Upvotes: 2

Views: 17790

Answers (2)

Paul
Paul

Reputation: 141819

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.

Upvotes: 9

Mark B
Mark B

Reputation: 200411

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"

Upvotes: 6

Related Questions