Environment variables size limit - how to overcome?

I am over the limit of characters that i can use for environment variables, is there any way around this? I am at 4299 characters and unfortunately i cannot shorten them at all. What should i do?

howdy @Munson1970,

i checked with the team on this and the character limit is only for one set in our UI, ones that you might need to use for functions. You can set additional variables in the netlify.toml file that will not count against the limit.

There is no workaround if you need them for functions, other than reducing size. The limit is described here:

1 Like

I do need 3 of the 4 for functions unfortunately and it is the shortest variable so id still have about 4239. Its because google service account private_keys are over 1700 characters and i need 2 of them.
So theres no other way i can do it?

Sadly, the only other way would be to not use EVs and hardcode the values in your code. Then, keep your repo private. As you can see, the limit is imposed by AWS and they have clearly mentioned that it can’t be increased.

1 Like

Yeah i understand they can’t increase the limit haha, i was just wondering if there was some other way i was unaware of. Currently i do have my repo as private and i have the value hardcoded in, if thats all i can do then so be it :stuck_out_tongue:

hi @Munson1970, sadly there isn’t another way! Sorry, i wish i had better news.

Its all good! Its kind of hacky but i decided im going to cut the variable in half and store half of it in an EV and hard-code the other half. Thank you for the responses regardless!

1 Like

if we hear about something changing re: env variable length, we’ll be sure to let you know!

1 Like

Hey there

I might be a bit late to the party, but I ran into this problem, too. It turns out there’s now a Netlify build plugin written for this exact scenario!

I wrote about it here — How to use really long environment variables on Netlify.

If your environment variable needs to preserve new lines (such as in the case of a private key), you’ll need do something like this on the environment variable:

process.env.PRIVATE_KEY.replace(/\\n/g, "\n")

Other than that, it worked a treat for me!

Hopefully that helps!

1 Like