Environment Vars Feature requests / Filter env vars to include in Lambda environment parameter

Feature request
Allow a Netlify function to have an override configuration that specifies which env vars to include in the lambda environment parameter when Netlify creates the Lambda on AWS. If there are >4096 env vars for the entire site but only 1KB needed for a function, the function configuration can select just those env vars that make up the 1KB and thus the Lambda deploy would not fail and thus the whole site deploy would not fail.

Original issue that prompted this feature idea
We recently ran into the 4KB limitation of environment variables in the Lambda functions. I’ve written about it in this support thread:

Build Fails – Invalid AWS Lambda parameters?.

Why is this bad?
The entire site deployment was broken because of this issue and we had no warning of the impending problem. We had no idea how close we were to this limit before-hand to proactively manage it. Since the total size of ALL site-wide env vars is counted and we had exceeded the 4096 size, we were left with no option but to eliminate/reduce env vars despite that not being the best design decision for the app and despite the fact that many were not even referenced in the Lambda functions.

We rely upon a /functions/lib folder for shared local util libraries that we write and use across many of our netlify functions. At this time, I believe this only works if the netlify functions live in the root of the functions folder. If we use the structure of putting a netlify function in it’s own directory inside of the functions folder then the the lib folder is no longer accessible. (I may be remembering this wrong). If that’s the case, then placement of a function’s env vars override could need to not rely upon the folder type configuration for a function. Instead it may be best to put this into the netlify.toml somewhere.

1 Like

This is a great feature request. I think the minimum viable mitigation is to tell you the problem, since we can detect that your env vars are too big when the deploy fails - but as you point out, you might not be aware that there is such a limit, or that you are hitting it - at least we could inform you in the build logs!

Your suggestion is more elegant but also much more intensive to implement.

Nonetheless, I don’t write the code, so I will suggest both and we’ll follow up here if either is implemented. Thanks so much for taking the time to suggest this so thoughtfully!

My pleasure and if any part of it’s open source I’d be happen to take a crack at it.

Thanks for the quick reply.

thanks for the offer to help, rob! Those two repo’s aren’t public, but I’ll mention your kind offer in the issue.

We’ll update this post as soon as we have something new!

It would be great if the input fields for environment variables would be bigger (or could expand), especially the value fields. We use the Netlify API to create them, but the way we use it in combination with GatsbyJS, we need to create single values that are JSON strings that can become quite long. Editing existing environment values for apps is something we do surprisingly often, and it would be very helpful if the web interface would allow us to do this more easily instead of us having to scroll inside a tiny input field or having to open up a separate text editor to copy paste it to and fro just to be able to see more text at once.