Skip to content

Add a deploy script for cost-history-collector - #853

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/848-cost-history-deploy
Oct 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/848-cost-history-deploy

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #848. Correctness audit 2026-10.

What this was

The one live Lambda nothing in this repo could ship:

LastModified: 2026-02-20T01:47:39Z
Schedule:     rate(1 hour), ENABLED

$ grep -rl cost-history-collector . | grep -v '^./.git'
CHANGELOG.md  .gitignore  docs/infra-account.md  .github/dependabot.yml
lambda/cost-history-collector/go.mod

No deploy script, no Makefile target, no CFN or SAM template.

It is not dead code. lambda/dashboard-api/cost_history.go serves
GET /api/cost-history from the spawn-cost-history table it fills — 2,161 items — and
the collector ran successfully for 3 users minutes before this was written. It was simply
unreachable from the repo, so Dependabot had spent eight months bumping a module that could
not get to production.

Verified that the existing gates actually see it

Modelled on deploy-scheduler-handler.sh precisely so the gates apply without needing new
ones — and then checked, because a gate that passes by not looking at the file is worth
nothing:

revert: remove the account assertion
  ❌ scripts/deploy-cost-history-collector.sh assigns EXPECTED_ACCOUNT but never
     compares it to the caller's account, so it asserts nothing

revert: s/put-retention-policy/describe-log-groups/
  ❌ ./scripts/deploy-cost-history-collector.sh deploys a function but never sets
     log retention

Hardening those scripts earned the hard way

  • The runtime is asserted on every deploy, not only on create.
    update-function-code does not change the runtime, so a script can declare
    provided.al2023 and redeploy forever while the function stays on provided.al2 — which
    is exactly what happened to scheduler-handler, deployed 2026-01 and still al2 in October
    (Nothing tracks deployed Lambda runtime versions: two are already stale (provided.al2, python3.11) and a runtime reaching EOL would be silent #716).
  • spawn:version is stamped from git describe --dirty, so deployed bytes trace to a
    commit and an uncommitted deploy says so. This is the only thing that would have revealed
    this function being eight months behind its source.
  • The package is built, not main.go — naming files ships a binary missing any source
    file added later.
  • AWS_REGION is ignored in favour of an explicit region, since honouring an ambient
    region is how a second scheduler-handler came to exist in us-west-2 while the stale one
    stayed in us-east-1.
  • The configuration-update error is not swallowed.

Architecture, timeout, memory, role and runtime were read from the live function rather
than guessed: x86_64, 300s, 512 MB, SpawnDashboardLambdaRole, provided.al2023.

One deliberate omission

It does not create the hourly EventBridge rule. The live one
(spawn-cost-history-collector-hourly) already exists, and a deploy script that also owned
the schedule would be able to silently change how often a cost collector runs. The create
path says so explicitly, since a freshly created function would otherwise never be invoked.

Verification

make check (all nested modules), make check-docs, changelog gate, semgrep 0 findings,
shellcheck clean, bash -n clean, scripts/lambda-deploy-census.sh passing.

Not run. This adds the script; deploying is a separate, live action.

@scttfrdmn scttfrdmn added this to the Correctness audit 2026-10 milestone Oct 11, 2026
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

It was the one live Lambda nothing in this repo could ship: invoked
hourly by an enabled EventBridge rule, last modified 2026-02-20, and the
only references to it anywhere were its own go.mod, a .gitignore entry, a
Dependabot entry and the changelog. No deploy script, no Makefile
target, no CFN or SAM template.

It is not dead code — lambda/dashboard-api/cost_history.go serves
GET /api/cost-history from the spawn-cost-history table it fills, which
holds thousands of hourly snapshots, and the function ran successfully
minutes before this was written. It was simply unreachable from the
repo, so Dependabot had spent eight months bumping a module that could
not get to production.

Modelled on deploy-scheduler-handler.sh so the existing gates apply
automatically rather than needing new ones. Verified by reverting each:
removing the account assertion fails TestDeployScriptsAssertTheAccount
NAMING the new script, and removing put-retention-policy fails the
census. A gate that passes because it never looked at the file is worth
nothing, so both were checked rather than assumed.

Carries the hardening those scripts earned the hard way: the runtime is
asserted on every deploy and not only on create (#716 — a script
declared provided.al2023 and redeployed for ten months while the
function stayed on provided.al2, because update-function-code does not
change the runtime); spawn:version is stamped from `git describe --dirty`
so deployed bytes trace to a commit, which is the only thing that would
have revealed this function being eight months behind its source; the
PACKAGE is built rather than main.go; and AWS_REGION is ignored in favour
of an explicit region, since honouring it is how a second
scheduler-handler came to exist in us-west-2.

It deliberately does NOT create the hourly EventBridge rule. The live
one already exists, and a deploy script that also owned the schedule
could silently change how often a cost collector runs.

Closes #848
@scttfrdmn
scttfrdmn force-pushed the feat/848-cost-history-deploy branch from 996e832 to 7d2eeca Compare October 11, 2026 23:07
@scttfrdmn
scttfrdmn merged commit 9c23847 into main Oct 11, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/848-cost-history-deploy branch October 11, 2026 23:25
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.

spawn-cost-history-collector is live and hourly, and nothing in the repo can deploy it

1 participant