Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
upload large javascript object as json file on aws s3 (efficient way)

Hi I have json response probably of size 150-200MB. Because of its size, I want to save it on aws s3 as json file instead of returning it to the client. Below this the code I m using currently.

async function uploadFileOnS3(fileData, s3Detail) {
  const params = {
    Bucket: s3Detail.Bucket,
    Key: s3Detail.Key_response,
    Body: JSON.stringify(fileData), // big fat js object
  };
  try {
    const stored = await S3.upload(params).promise();
    console.log("file uploaded Sucessfully ", stored);
  } catch (err) {
    console.log(err);
  }
  console.log("upload exit");
}

I m concern about JSON.stringify(fileData) operation. assuming this function will be part of a aws lambda, won't it take huge resources to parse it as string?

is there any other efficient way to save javascript object as json on aws s3 bucket?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't really have to stringify the JSON file. You can pass a stream as a body:

async function uploadFileOnS3(fileData, s3Detail) {
    const params = {
        Bucket: s3Detail.Bucket,
        Key: s3Detail.Key_response,
        Body: fileData, // remove stringify from here
    };
    try {
        const stored = await S3.upload(params).promise();
        console.log("file uploaded Sucessfully ", stored);
    } catch (err) {
        console.log(err);
    }
    console.log("upload exit");
}

exports.handler = async (event) => {
    // We create a stream
    const stream = fs.createReadStream("/tmp/upload.json");

    // Pass the stream to the upload function
    await uploadFileOnS3(stream, {
        Bucket: "bucket_name",
        Key_response: "upload.json"
    });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!