ShamaMaganur
ShamaMaganur

Reputation: 1

Reading file from S3 bucket and writing in current directory using lambda function

  1. Want to read a file from S3 bucket (ex: text.txt) using lambda
  2. write file in current directory, to location(ex: __dirname + 'text.txt') using lambda

I am able to read file

let txtfilepath = __dirname + 'text.txt'
var params = {   

enter code here
Bucket: bucketname,   
Key: filepathInS3
}; 

S3.getObject(params, function(err, data){   
if (err)
      console.error(err.code, "-", err.message);
      return (err);  
enter code here
fs.writeFile(txtfilepath, data.Body, function(err){
    if(err)
    console.log(err.code, "-", err.message);
    return (err);   
});
});

getting error - read-only file system

Upvotes: 0

Views: 514

Answers (1)

Anon Coward
Anon Coward

Reputation: 10832

The only directory you can write to in the Lambda execution environment is /tmp, all other folders are read-only.

Upvotes: 3

Related Questions