# Lambda was unable to configure your environment variables: exceeded the 4KB limit

AWS error fixes · Updated 17 November 2026

**Short answer:** The total size of all environment variables on a Lambda function, keys and values together, can't exceed 4 KB, and the limit can't be raised. Move large or numerous values out: put configuration in AWS Systems Manager Parameter Store or AppConfig, secrets in Secrets Manager, and read them at start-up (cached for the life of the execution environment). Keep only small values, such as parameter names, in environment variables.

## What it looks like

```
An error occurred (InvalidParameterValueException) when calling the UpdateFunctionConfiguration operation:
Lambda was unable to configure your environment variables because the environment variables you have
provided exceeded the 4KB limit. String measured: {"DB_HOST":"...","FEATURE_FLAGS":"..."}
```

The `String measured` part shows how Lambda counts: it serialises all variables as JSON and measures that, so quotes, colons and commas count too. It's a hard quota, not something Service Quotas can increase.

## Find what's using the space

```
aws lambda get-function-configuration --function-name orders-api \
  --query Environment.Variables --output json \
| python3 -c 'import json,sys; v=json.load(sys.stdin); [print(len(k)+len(x), k) for k,x in sorted(v.items(), key=lambda i: -len(i[1]))]' | head
```

Typical culprits: certificates or keys pasted as values, JSON blobs of feature flags or routing tables, long connection strings, and tooling that injects many variables (some frameworks and deploy plugins add a dozen or more).

## Move values out

| Value type | Where to put it |
|---|---|
| Secrets (passwords, API keys) | Secrets Manager; read with the SDK or the AWS Parameters and Secrets Lambda Extension, which caches |
| Plain configuration, per environment | Parameter Store (Standard parameters up to 4 KB each, Advanced up to 8 KB); store one JSON parameter instead of many variables |
| Feature flags, frequently changed config | AWS AppConfig with its Lambda extension |
| Large static data | A file in the deployment package or a layer, or an S3 object read once per cold start |

Then leave a pointer in the environment, for example `CONFIG_PARAM=/orders-api/prod/config`, and load it outside the handler so it's fetched once per execution environment, not per invocation.

## Watch out for

- **Start-up latency and throttling**: fetching parameters on every invocation is slow and can hit Parameter Store throughput limits. Cache in a global variable or use the extension.
- **The execution role** now needs `ssm:GetParameter` or `secretsmanager:GetSecretValue` (and `kms:Decrypt` for customer managed keys). Without it you'll get [AccessDenied](https://cloudconsole.dev/errors/accessdenied-no-identity-based-policy-allows) at runtime instead of a deploy error.
- **Updates replace the whole set**: `update-function-configuration --environment` replaces all variables, so scripts that set one variable can delete the rest. See [update Lambda environment variables](https://cloudconsole.dev/how-to/update-lambda-environment-variables).
- **Secrets in environment variables** are visible to anyone with `lambda:GetFunctionConfiguration`; moving them out is worth doing anyway.

## Questions

### What is the Lambda environment variable size limit?

4 KB in total for all of a function's environment variables, measured as the serialised keys and values. It can't be increased.

### How do I store more configuration for a Lambda function?

Keep it in Parameter Store, AppConfig or Secrets Manager and load it at start-up, leaving only the parameter name in an environment variable.

### Does the 4 KB limit include the variable names?

Yes. Keys, values and the JSON punctuation Lambda uses to measure them all count.

## When this happens away from your desk

Configuration changes that fail mid-deploy can leave functions on old settings. CloudConsole, a phone app for AWS, is being built to show Lambda errors, logs and alarms on your phone, so you can confirm a release landed cleanly.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Working with Lambda environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html)
- [Lambda quotas](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)

## Related

- [How to update Lambda environment variables](https://cloudconsole.dev/how-to/update-lambda-environment-variables)
- [aws ssm get-parameter](https://cloudconsole.dev/cli/ssm-get-parameter)
- [aws secretsmanager get-secret-value](https://cloudconsole.dev/cli/secretsmanager-get-secret-value)
- [aws lambda update-function-configuration](https://cloudconsole.dev/cli/lambda-update-function-configuration)
- [Unzipped size must be smaller than 262144000 bytes](https://cloudconsole.dev/errors/lambda-unzipped-size-too-large)
- [CodeStorageExceededException: Code storage limit exceeded](https://cloudconsole.dev/errors/lambda-codestorageexceeded)

---

Source: https://cloudconsole.dev/errors/lambda-environment-variables-exceeded-4kb

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
