How to save a file to a tmp/temp folder in lambda?

1

is it possible to save a file , where the lambda is running. i am using a javascript library to manipulate some text , same code below . I am using a thirdparty async function to get some data and as the returned array can be quite big, i think it is failing , when i try to upload it to s3. how can i save it to a file in /tmp/file.txt or where the lambda is running , so that i can debug to see at least the data is being returned and then is it possible to upload the file to and s3 and then delete it locally?

thirdparty.func()
.then(function(data){
    //data returned is an array
   data.forEach(function(val){
          //write val to a local file 
   })
})
.catch(e=>{console.log(e)});
질문됨 2년 전23324회 조회
1개 답변
1

You can write files to /tmp in your Lambda function. By default the size is limited to 512 MB, but you can increase it up to 10 GB. Note that the /tmp is inside the function's execution environment and you do not have access to it from outside the function. If you want to save a file that you can access it externally, you should either save it to S3 or mount an EFS volume and write the file there.

Inside your Lambda function you can do almost anything, so yes, you can copy files to S3 and you can delete them.

profile pictureAWS
전문가
Uri
답변함 2년 전
profile pictureAWS
전문가
검토됨 10달 전
  • @Uri - thanks. i'm having an issue with reading the file . is there a pre-built lambda layer for aws cli sdk for node js that i can use with my lambda and may be issue commands like aws s3 cp /.tmp.sample.txt s3://bucket in my nodejs lambda?

  • I am not familiar of any such extension. The following code should upload a local file to S3:

    const uploadFile = (fileName) => {
        const content = fs.readFileSync(fileName);
    
        const params = {
            Bucket: BUCKET_NAME,
            Key: OBJECT_NAME,
            Body: content
        };
    
        s3.upload(params, function(err, data) {
            if (err) {
                throw err;
            }
        });
    };
    

    I suggest that you await for it to complete.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠