I'm having issues writing a file to the tmp folder in lambda instance.
const fs = require('fs-extra');
const os = require('os');
const cwd = process.cwd();
const buffer = Buffer.from(arrayBuffer, 'base64');
const newFileName = 'myFile.png';
const temporaryImageDirectory = os.tmpdir();
// filePath works locally, but doesn't work deployed to lambda.
// No errors in cloudwatch
const filePath = `/tmp/${newFileName}`; // works locally
// filePath1 works locally, but doesn't work deployed to lambda.
// No errors in cloudwatch
const filePath1 = `${cwd}/${newFileName}`; // works locally
// filePath2 works locally, but doesn't work deployed to lambda.
// Cloudwatch Error: EROFS: read-only file system, open '/var/task/myFile.png'
const filePath2 = `${temporaryImageDirectory}/${newFileName}`; // works locally
console.log('FILE PATH: ', filePath);
console.log('FILE PATH1: ', filePath1);
console.log('FILE PATH2: ', filePath2);
fs.writeFile(filePath, buffer, 'utf-8')
.then(() => {
webhook.sendFile(filePath);
})
.catch((e) => {
console.log('Error', e);
});
console.log FILE PATHs in cloudwatch
filePath1 full error
Error [Error: EROFS: read-only file system, open '/var/task/myFile.png'] {
errno: -30,
code: 'EROFS',
syscall: 'open',
path: '/var/task/myFile.png'
}
How can I get the file to get stored temporarily successfully so that I can send it to it's destination webhook? I have no issues sending the file locally via serverless offline, but obviously in AWS is a little different. filePath, filePath1, and filePath2 all don't work in AWS, but work locally. What am I missing? Any help is appreciated!