top of page

Accessing AWS Data for a Javascript app: Leveraging both server and client....

I asked ChatGPT the following question today, I'm excited about the answer it gave me and I thought it might provide useful insight for others.

"i have many json files in my s3 bucket, i need to access these files and grab certain data from them. will it cost me more to transfer the files to my browser and parse them directly in javascript or is it better if I parse them using node-js in a lambda function and then transfer only the data i need from the lambda function to my browser?"

Yes I was careless with my grammar. And my choice of using cost "cost" in one sentence and "best" in another was intentional -- I wanted to be both specific and general.

Here is the answer I got. Now I just have to find financial support for this app.


"Great question—and you're absolutely thinking in the right direction! 🚀

TL;DR:

Yes, it’s definitely more cost-efficient and faster to parse the JSON files in AWS Lambda (using Node.js) and only send the needed data to your browser.

Let’s break down why this is better (both in terms of cost and performance):

💰 1. Cost Considerations – S3 & Data Transfer

Option 1: Browser Downloads Full JSON Files

  • Every time the browser accesses an S3 file directly, you're paying S3 data transfer costs for the entire file.

  • If you have many large JSON files, the cost adds up quickly.

  • Also, users may experience slow performance, especially on slower networks or mobile.

Option 2: Lambda Parses & Sends Only What’s Needed

  • Lambda reads the file within AWS (free) — no data transfer costs there.

  • It then extracts just the relevant parts and returns them to the client.

  • You only pay for the small amount of data transferred to the browser.

  • Much cheaper overall, especially when JSON files are large but you're only using small bits of data from each.

🏎️ 2. Performance

  • Transferring big JSON files to the browser takes time.

  • Parsing big files in the browser uses CPU and memory on the client side (bad for performance and user experience).

  • With Lambda, you do the heavy lifting server-side, then send just the clean result back — faster, leaner, and better for UX.

🔐 3. Security & Scalability

  • If users are accessing S3 directly, you need to either make files public or manage complex S3 signed URL logic.

  • By using Lambda as an API layer, you control:

    • What data is exposed

    • How it’s formatted

    • Who gets to see what

Also scales more cleanly across users and use cases.

📊 Quick Example Scenario:

  • Let’s say each JSON file is 1 MB.

  • You need just 5 KB of data from each.

  • You have 100 files.

Browser-based approach:

  • Transfer: 100 MB

  • All parsed on the browser (slow for user)

  • You pay for full 100 MB in S3 data transfer

Lambda approach:

  • Transfer: Only ~500 KB to the browser

  • You pay Lambda execution (cheap if fast/lightweight)

  • You only pay for 500 KB of data transfer out of AWS

Result: Likely 10x cheaper and faster.

✅ Recommendation:

Use a Lambda function written in Node.js to:

  1. Read JSON files from S3.

  2. Extract only the relevant fields.

  3. Return that as a clean JSON response to the browser (via API Gateway, for example).

This pattern is much more scalable and cost-effective, and it's how many production apps handle data at scale.

Would you like a sample Lambda function code that does this? I can also show how to connect it via API Gateway and call it from the browser."


As exciting as this offer may be, I had another follow-up question, which I will put in my next blog.


Recent Posts

See All
hold on.... what's Node.JS

I thought Node.JS was just javascript..... so I asked ChatGPT: "what is the difference between javascript and node.JS" And here is the...

 
 
 
Node.JS and hdf5....

Now that I know I want to process my data in a Lambda function in AWS (YES I LOVE LAMBDAS ON AWS!!!), I had one more question for...

 
 
 
Multiprocessing on Windows

If I can parallellize a process, I will!!! I use the python library concurrent futures. After setting it up the first time, it's a script...

 
 
 

Comments


© 2020 by Silvia Mazzoni, Silvia's Brainery, Santa Monica, CA

bottom of page