Skip to content

fix(E3697): measure Lambda environment size as compact JSON bytes - #4860

Merged
kddejong merged 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:fix-4858-e3697-json-overhead
Oct 28, 2026
Merged

kddejong merged 1 commit into
aws-cloudformation:mainfrom
Varshith-Kali:fix-4858-e3697-json-overhead

Conversation

@Varshith-Kali

Copy link
Copy Markdown
Contributor

Summary

E3697 summed the lengths of environment variable keys and values, but Lambda measures the variables map as compact JSON ({"KEY":"value",...}). The structural characters (four quotes and a colon per variable, a comma between variables, two braces) add 6n + 1 bytes for n variables, so the rule undercounted: with 100 variables, 3,496 bytes of keys plus values is 4,097 bytes of JSON, which the rule treated as 600 bytes under the limit while Lambda rejects the deployment.

This measures the UTF-8 byte length of the compact JSON encoding (separators=(",", ":"), ensure_ascii=False so multi-byte characters count as UTF-8 bytes, consistent with #4841) instead of summing key/value lengths.

Verification

  • Reproduced with generated templates: a 100-variable map at 4,101 JSON bytes now fires (E3697 Lambda environment variables total size (4101) exceeds the 4 KB (4096 bytes) limit); a map at exactly 4,096 JSON bytes stays silent.
  • New regression tests: boundary at exactly 4096 (silent) and 4097 (fires), the 100-variable structural-overhead case, non-ASCII UTF-8 byte counting, and JSON escaping. The 5 tests encoding the new behavior fail pre-fix and pass post-fix; the full test_function_environment_size.py suite (13 tests) and the whole lmbd rule directory (218 tests) pass. Ruff check and format clean.

Note: this composes with the pending #4841 (intrinsic resolution and UTF-8 counting); I will rebase once that lands.

Fixes #4858

@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Hi team, on this fix(E3697) PR: the [CI] Test PR workflow run on the current head is still parked waiting for a first-time-contributor approval (action_required). Could a maintainer approve the run so CI can proceed? Thanks.

@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Hi @kddejong, friendly follow up: the CI runs on this PR are still parked at the first-time-contributor approval gate (action_required), so the checks cannot start until a maintainer approves the run. Could you approve it when you have a moment? Thanks!

Lambda measures the environment variables map as compact JSON, so the
structural characters (four quotes and a colon per variable, commas
between variables, two braces) count toward the 4 KB limit. Summing
key and value lengths undercounts by 6n + 1 bytes for n variables,
letting oversized maps through. Measure the UTF-8 byte length of the
compact JSON encoding instead.

Fixes aws-cloudformation#4858

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@kddejong
kddejong force-pushed the fix-4858-e3697-json-overhead branch from 8583bcf to e23ea93 Compare October 28, 2026 19:05
@kddejong
kddejong merged commit f302ad0 into aws-cloudformation:main Oct 28, 2026
22 checks passed
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.69%. Comparing base (cf5360c) to head (e23ea93).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4860   +/-   ##
=======================================
  Coverage   94.69%   94.69%           
=======================================
  Files         442      442           
  Lines       16091    16092    +1     
  Branches     3121     3121           
=======================================
+ Hits        15237    15238    +1     
  Misses        470      470           
  Partials      384      384           
Flag Coverage Δ
unittests 94.68% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E3697: total excludes the JSON quotes, colons, commas and braces that Lambda counts toward the 4 KB environment limit

2 participants