r/Netlify • u/max1302 • Oct 22 '25
Hit the 4KB environment variable limit on free tier - any workarounds besides compressing secrets?
Hey everyone,
I'm deploying a Next.js app to Netlify (free tier) and running into the AWS Lambda 4KB environment variable limit. My deploy is failing with:
Failed to create function: invalid parameter for function creation:
Your environment variables exceed the 4KB limit imposed by AWS Lambda.
Please consider reducing them.
I have about 30 environment variables, and the main culprit is a Google Service Account private key (~1.7KB). The rest are standard API keys, webhook URLs, and public Next.js env vars.
What I've considered:
- Compressing the key (replacing newlines with
\n) - saves maybe 60 bytes, might not be enough - Storing secrets in Supabase - works but requires code changes to fetch secrets at runtime
- Bitwarden Secrets Manager - same issue, needs code refactoring
- Switching to Vercel (🐸)
My question: Is there any Netlify-native solution I'm missing? Something like:
- Automatically storing large env vars in Netlify Blobs and lazy-loading them?
- A way to exclude certain env vars from Lambda functions (I know this exists in Pro tier scoping)?
- Any build-time tricks that don't require runtime code changes?
I love Netlify but this Lambda limitation is frustrating when other platforms handle large secrets better. Any suggestions from folks who've dealt with this?
Update: Yes, I know I can refactor my code to fetch secrets from external storage, but I'm curious if there's a cleaner Netlify-specific solution I'm overlooking.
2
u/hrishikeshkokate Netlify | Software Engineer Oct 22 '25
The limit is not limited to free tier.
In any case, we're soon (not exactly sure how soon) gonna release a platform level solution. Meanwhile, you could:
You could also just dynamically create a .env file during the build and use dotenv in your function to load all variables in process.env
I had attempted to ship a PR that would automatically use dotenv and include the env files as a workaround to this 4 KB limit, but the devs mentioned they're working on a platform level solution and thus didn't ship my PR.
1
u/shgysk8zer0 Oct 22 '25
I had the same issue recently and ended up using encryption with the key as an environment variable. Stored things encrypted in the repo. Built a little
Proxywrapper to keep things pretty similar, although it now needsawait.1
u/-SLOW-MO-JOHN-D Feb 26 '26
67