fix(lambda): enforce 4 KB environment variable limit (#7995) (#8055)

Validate the compact UTF-8 JSON environment before function creation or configuration mutation. Both paths previously accepted the 5,000-character value reported in #7995. Cover exact byte boundaries, aggregate variables, Unicode, JSON escaping, and rejected-update atomicity through the AWS SDK.

Stop quota serialization through a bounded UTF-8 counting sink without allocating complete JSON and byte-array copies. Keep unchanged legacy environments out of CloudFormation configuration updates while validating changed variables and preserving environment removal. Add early-stop, one-megabyte input, Unicode buffer-boundary, and legacy-stack rollback regressions.

Include AWS's String measured diagnostic while retaining at most 5,120 UTF-8 bytes and terminating larger input early. Drop incomplete trailing UTF-8 characters before adding an ellipsis. Keep the 1 MB robustness request on CreateFunction, and assert every SDK configuration-update body stays below the separate 5,120-byte request limit. Cover complete measured JSON and bounded Unicode previews.
This commit is contained in:
jwoa95 authored and GitHub committed 2026-11-12 07:51:13 -04:00
1 parent 33968bca39
commit b2fa9b3f6c
6 files changed
+526 -4

No files matched your search

+16
View File
@@ -75,6 +75,22 @@ Floci Lambda runs your function code locally inside real Docker containers - clo
supported ranges before changing any stored settings. A rejected value returns
`InvalidParameterValueException` and leaves the function configuration unchanged.
`CreateFunction` and `UpdateFunctionConfiguration` enforce the 4 KB environment-variable
limit. The compact JSON `Variables` object must fit within 4,096 UTF-8 bytes, including
keys, values, punctuation, and JSON escaping, as described in the
[AWS deployment guidance](https://docs.aws.amazon.com/lambda/latest/dg/troubleshooting-deployment.html).
An oversized environment returns HTTP 400 with `InvalidParameterValueException` before
creating a function or changing any stored configuration. Omitting `Environment` on an
update preserves the existing variables; an empty `Variables` object clears them.
Validation stops serializing oversized input without allocating full JSON and UTF-8 copies.
Quota errors include AWS's `String measured:` detail. The diagnostic retains up to 5,120
UTF-8 bytes of compact variables JSON; larger inputs end with `...`, dropping any incomplete
trailing UTF-8 character. This keeps diagnostic allocation and serialization bounded.
CloudFormation omits unchanged environment variables during in-place configuration updates,
so a function persisted before quota enforcement can retain an oversized environment when
another property changes. Changing or removing its variables still updates the environment
and enforces the quota.
The event invoke configuration is stored and returned as AWS does, and `AWS::Lambda::EventInvokeConfig`
provisions it from a stack. A SAM function's `EventInvokeConfig` expands into that resource as
`sam deploy` does: on `$LATEST`, or on the `AutoPublishAlias` alias, with the inline role policy for