title: Saving file to /tmp in lambda from inside of a folder
body: <p>I have a task of downloading and uploading files to s3 using lambda, the scenerio is like</p>
  <ul>
  <li>Download a file from s3 bucket1(request folder) to lambda</li>
  <li>Upload the same file to s3 bucket2(request folder) from lambda</li>
  </ul>
  <p>Both the <code>downloadFiles</code> and <code>uploadFiles</code> fn are inside <code>utils/s3.js</code> inside the root directory(var/task/) in lambda</p>
  <p>Here is my <code>utils/s3.js</code> downloadFiles fn</p>
  <pre><code>exports.downloadFiles = async () =&gt; {
    try{
      const location = path.join( __dirname , `../tmp/text.txt`);
      console.log(location); // prints /var/task/tmp/text.txt
      console.log(__dirname); // prints /var/task/utils
      const params = {
        Bucket: 'bucket1',
        Key: `request/text.txt`
      };
  
      const { Body } = await s3.getObject(params).promise();
      fs.writeFileSync(location, Body);
      return;
    }catch(e){
      throw new Error(e.message);
    }
  };
  </code></pre>
  <p>Now there are two cases,</p>
  <ul>
  <li><p>If I create a folder in the root directory <code>tmp</code>, it gives this error</p>
  <p><em>&quot;EROFS: read-only file system, open '/var/task/tmp/text.txt'&quot;</em></p>
  </li>
  <li><p>If I don't then</p>
  <p><em>&quot;ENOENT: no such file or directory, open '/var/task/tmp/text.txt'&quot;</em></p>
  </li>
  </ul>
  <p>Now I have read most of the answeres on stackoverflow, I know I am supposed to save files to <code>/tmp/filename,</code> but how come I do the same and it doesn't work, where am I going so wrong?</p>