feat: allow using .env files to get around 4 KB env size limits #6667
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This could be one "quick" way we can solve the 4 KB ENV limit on AWS Lambda.
Some time ago, I wrote this plugin: https://github.com/hrishikesh-k/netlify-plugin-bundle-env that would allow users to include their build-time env into Functions. It kinda works, but has various shortcomings, while being very easy to break. Instead, I think a simpler and a more reliable solution would be to simply generate a
.env
file during a build and include it in the Function.Next Runtime already does that, except the "reading" of the
.env
file is handled by Next.js itself, as far as I'm aware. I think other frameworks might also handle the reading themselves, but for other users, this would still come in handy. There have been several users who have run into this in the past as well as this was most recently experienced here: https://netlify.zendesk.com/agent/tickets/424746. Based on npm stats: https://www.npmjs.com/package/netlify-plugin-bundle-env, my package has 4k weekly downloads, so there's at least some demand to this.What do you all think about this approach?
The reason
dotenv
is a dynamic import is because not everyone will have that package installed (or even need it). My plugin would handle adding thedotenv
in the bundle, so whoever is using my plugin should be fine, but we don't want to break this for others.