When deploying - Deploy did not succeed with HTTP Error 400:

i’ve added a new serverless function and an extra env var and when trying to deploy i get this?

any idea why? sorry if this was mentioned before. thanks

update: i’ve realised that the issue is the dropbox token which is very long.
how can i solve this issue?
5:44:53 PM: Failed to create function: invalid parameter for function creation: Your environment variables exceed the 4KB limit imposed by AWS Lambda. Please consider reducing them.
5:44:53 PM: Failed to create function: invalid parameter for function creation: Your environment variables exceed the 4KB limit imposed by AWS Lambda. Please consider reducing them.
5:44:54 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
5:44:52 PM: Deploy site
5:44:52 PM: ────────────────────────────────────────────────────────────────
5:44:52 PM: ​
5:44:52 PM: Starting to deploy site from ‘’
5:44:52 PM: Calculating files to upload
5:44:52 PM: 0 new file(s) to upload
5:44:52 PM: 4 new function(s) to upload
5:44:53 PM: Failed to upload file: hello-world
5:44:53 PM: Failed to upload file: dropboxIntegration
5:44:53 PM: Failed to upload file: firebase
5:44:53 PM: Failed to upload file: firebaseAddData
5:44:53 PM: Section completed: deploying
5:44:53 PM: ​
5:44:53 PM: Error deploying
5:44:53 PM: ────────────────────────────────────────────────────────────────
5:44:53 PM: ​
5:44:53 PM: Error message
5:44:53 PM: Deploy did not succeed with HTTP Error 400: [PUT /deploys/{deploy_id}/functions/{name}][400] uploadDeployFunction default &{Code:400 Message:Failed to create function: invalid parameter for function creation: Your environment variables exceed the 4KB limit imposed by AWS Lambda. Please consider reducing them.}
5:44:53 PM: Failed to create function: invalid parameter for function creation: Your environment variables exceed the 4KB limit imposed by AWS Lambda. Please consider reducing them.
5:44:53 PM: Failed to create function: invalid parameter for function creation: Your environment variables exceed the 4KB limit imposed by AWS Lambda. Please consider reducing them.
5:44:53 PM: ​
5:44:53 PM: Error location
5:44:53 PM: At deploy the stage with HTTP status code ‘400’
5:44:53 PM: ​
5:44:53 PM: Resolved config
5:44:53 PM: build:
5:44:53 PM: environment:
5:44:53 PM: - DROPBOX_ACCESS_TOKEN
5:44:53 PM: - EVENTIX_CLIENT_ID
5:44:53 PM: - EVENTIX_CLIENT_SECRET
5:44:53 PM: - EVENTIX_CODE_KEY
5:44:53 PM: - EVENTIX_COMPANY_ID
5:44:53 PM: - FIREBASE_SERVICE_ACCOUNT
5:44:53 PM: publish: /opt/build/repo
5:44:53 PM: publishOrigin: default
5:44:53 PM: functionsDirectory: /opt/build/repo/netlify/functions
5:44:53 PM: headers:
5:44:54 PM: - for: /*
values:
access-control-allow-origin: ‘*’
headersOrigin: config
5:44:54 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:44:54 PM: Failing build: Failed to build site

hey there, if you’ve confirmed the dropbox token length to be the reason you’re hitting this error, you can try this build plugin and scope your environment variables to builds which should help prevent you from hitting that limit

Thanks Marcus!

although i have one minor problem. I am using the free netlify plan which doesn’t allow me to scope my env variables to builds. is there another way of avoiding that 4kb limit? if not, i guess i ll have to go with the paid plan.

Hi @Renze_ten_Cate

The ability to set specific scopes for environment variables (like limiting them to just Builds, Functions, Runtime, or Post processing) is indeed a feature available only on Pro and Enterprise plans, as mentioned in the documentation Environment variables overview.

Regarding the 4KB limit you mentioned, the documentation states that environment variable values can contain up to 5,000 characters (which is 5KB), and keys can contain up to 255 characters. This is mentioned in the Limitations section.

Unfortunately, there are no specific workarounds for the free plan to avoid these limits. If you’re hitting the character limit for your environment variables, upgrading to a Pro plan would be the most straightforward solution.