Skip to content

SAM packages the entire CodeUri directory, so the ttl-reaper deploys at 75.7 MiB instead of ~7 MiB (and would ship .deploy-params.yaml) #645

Closed

Description

@scttfrdmn

Found while fixing #637. Untracking that 22 MiB binary stopped it being committed; it is still built into the same directory — and that directory is what SAM uploads.

Measured, in production

$ aws lambda get-function-configuration --function-name <fn> --query CodeSize
spawn-ttl-reaper-production              79387256  # 75.7 MiB
spawn-autoscale-orchestrator-production   7457417  #  7.1 MiB

The reaper's real artifact is a single bootstrap binary — roughly the 7 MiB the autoscale function shows. It is deployed at 75.7 MiB, a >10x inflation, on the one component whose job is guarding against runaway cost.

Mechanism (read from the installed SAM CLI, not assumed)

lambda/ttl-reaper/template.yaml and lambda/autoscale-orchestrator/template.yaml both set CodeUri: ., and their Makefiles run sam deploy --template-file template.yaml --resolve-s3 from inside that directory. SAM CLI 1.166.2, samcli/lib/package/utils.py:283:

for root, _, files in os.walk(source_root, followlinks=True):
    for filename in files:

No filtering of any kind — every file, dotfiles included.

What rides along

Local directory sizes — what a make deploy right now would upload:

lambda dir size contents of note
ttl-reaper 96 MB ttl-reaper dev binary (74 MB), function.zip (26 MB)
pipeline-orchestrator 39 MB no explicit CodeUri
autoscale-orchestrator 22 MB the #637 binary — untracked, still built here

Three classes of junk:

  1. Stray dev binaries. go build ./... writes <name> after the module directory. Exactly A 22 MiB compiled binary is tracked in git at lambda/autoscale-orchestrator/autoscale-orchestrator #637's binary.
  2. A redundant nested zip. Each Makefile runs zip function.zip bootstrap, but sam deploy ignores function.zip and zips the directory — so function.zip, holding a second copy of bootstrap, is packaged inside the deployment zip. Already compressed, hence near-incompressible: that is why 96 MB of files only squeezed to 75.7 MiB.
  3. GoReleaser's release artifact. The .goreleaser.yaml:25 before-hook writes bootstrap and ttl-reaper_lambda_linux_arm64.zip into lambda/ttl-reaper/ (No supported way to run the TTL reaper in your own account, so governed orgs can't have reaper coverage at all #625). After a release build, that zip is in the CodeUri set too.

The part that matters more than size

lambda/ttl-reaper/Makefile:50-53 generates .deploy-params.yaml inside the CodeUri: . directory, immediately before sam deploy, holding every deploy parameter including NotifyUrl — which the Makefile's own comment (line 55) calls "a Slack webhook secret". Because SAM's walk includes dotfiles, that file is uploaded into the deployment package, readable by anyone with lambda:GetFunction.

To be precise about severity: nothing is leaked right now. The local file's NotifyUrl is empty (0 matches for hooks.slack.com). But make deploy NOTIFY_URL=https://hooks.slack.com/... is the documented usage (Makefile:14), so this is a live trap rather than a past incident. Whether a webhook was ever passed on a real deploy is worth settling — if so it is sitting in the deployed package and should be rotated.

The repo is public, so the .go sources being shipped is not itself a disclosure.

Fix

Build into a dedicated build/ subdirectory holding only bootstrap, and point CodeUri explicitly at it in all three templates. The guarantee is structural: if the directory holds one file, the zip holds one file, regardless of what SAM filters.

sam build + Metadata: BuildMethod: makefile is the AWS-documented route and would also work, but it changes the deploy workflow and these Makefiles encode hard-won invocations — notably ttl-reaper's file://-params-file workaround for sam's parameter-overrides regex (Makefile:25-32). A CodeUri change plus a build directory gets the same result with a much smaller blast radius on a deploy path that touches a live production reaper.

Plus a drift gate asserting that every SAM template sets CodeUri explicitly and never to ., that the directory contains only bootstrap, and that .deploy-params.yaml is never inside a CodeUri directory.

Not in scope

  • Shrinking already-deployed packages — a redeploy does that.
  • The deploy.sh lambdas (dashboard-api, dashboard-websocket*, alert-*). They use aws lambda update-function-code --zip-file with an explicit zip and are already narrow. This is specific to the three SAM ones.
  • A real sam deploy as verification: that touches the live production reaper, so it stays an explicit, separate action.

Activity

  1. scttfrdmn commented on Oct 3, 2026

    @scttfrdmn
    ContributorAuthor

    Correcting two numbers in the issue body before they get quoted. I measured rather than inferred, and one of my claims was wrong.

    I wrote that the reaper's real artifact is "roughly the 7 MiB the autoscale function shows" and called it a ">10x inflation". That inferred the reaper's binary size from a different function's, which was unfounded — the reaper has far more dependencies. Measured by driving SAM's own make_zip_with_permissions over the fixed build/ directory:

    lambda bootstrap packaged zip entries currently deployed
    ttl-reaper 66 MB 25.2 MiB 1 75.7 MiB
    autoscale-orchestrator 15 MB 7.8 MiB 1 7.1 MiB
    pipeline-orchestrator 38 MB 17.1 MiB 1 (not found in infra/us-east-1)

    So the real numbers:

    • ttl-reaper: 75.7 MiB → 25.2 MiB, a ~3x reduction. Not 10x. Still ~50 MiB of pure junk per deploy, and still worth fixing, but I overstated it.
    • autoscale-orchestrator is not currently bloated. Its deployed 7.1 MiB is essentially a clean single-bootstrap package (a fresh build zips to 7.8 MiB). Its last deploy must have run from a clean directory. The exposure there is latent — the next deploy from a dirty tree would inflate it — not active. The issue body implied otherwise.

    What is unchanged: the mechanism (os.walk with no filtering, no .samignore, dotfiles included), the .deploy-params.yaml trap, and pipeline-orchestrator's implicit-cwd packaging. The fix also now has a hard guarantee rather than an estimate — entries=1, verified against SAM's real zipper, for all three.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions