@perry We just spent a whole day tracking down a deployment issue that turned out to be caused by this issue. The deployment logs on the netlify site did not shed any light on the real root cause and we only found it after doing a local build and deploy from the netlify-cli.
Once we saw the extra error information in the console output from the local deploy attempt we googled it and the only thing we found mentioning it was this post, so thank you!
That said, this should be documented in Netlify and possibly mentioned in the environment variables blog post @swyx wrote a little while back. We have a lot of environment variables and to get around this limitation was a real effort. We had to reduce the size of variable names and the size of values where possible (build the URLs in code with one key value from the env var instead of just putting the whole URL in the env var for instance). Had we known that we had an upper limit of 4096 bytes for all variables combined we would have utilized a different solution.
Now that we have compressed the sizes of the env var names and eliminated some that were optional, we have gotten our total size down to 3200 bytes which considering we are still actively developing, I suspect only buys us time until this becomes an issue again after adding more env vars. If you have any recommendations for how to work around this when the legitimate need is for more than 4096 bytes worth of env vars, I would love to discuss that with someone.
Maybe putting a counter of how close you are to the limit in the site environment config section would be a good idea but at the least document it on the environment variables docs page as a start. Oh yeah the deploy logs on app.netlify.com should show the real reason the functions fail too.
Some background references from AWS are Using Lambda environment variables - AWS Lambda
In the second link above is where AWS says the total of all environment variables cannot exceed 4KB.
Thanks for the awesome service!
Rob
EDIT: Added a feature request for allowing functions to specify a subset of environment variables to specify in the Lambda creation rather than using all available.