hyperframes icon indicating copy to clipboard operation
hyperframes copied to clipboard

feat(lambda): add SAM template and sample events for AWS deployment

Open jrusso1020 opened this issue 6 months ago • 1 comments

What

Adds examples/aws-lambda/ — a reference SAM template that deploys the HyperFrames Lambda handler from PR 6.1 alongside the Step Functions state machine, S3 bucket, IAM roles, and CloudWatch alarm needed to run distributed renders end-to-end on AWS.

This is PR 6.2 of the 8-PR Phase 6 stack. Stacked on top of #878 (PR 6.1: handler + ZIP).

Why

PR 6.1 produced a deployable ZIP but had nowhere to put it. This PR is the deployment surface — what sam deploy --guided creates in a user's own AWS account. Step Functions is the AWS-native fan-out primitive (Map state), fits Lambda's 15-minute per-invocation cap, and gives per-stage visibility into Plan / RenderChunk / Assemble timing.

The template is purely a reference for OSS adopters; PR 6.4 (CDK) and PR 6.5 (hyperframes lambda deploy CLI) ship the same topology through alternative deployment surfaces.

How

State machine choreography:

Plan
  ↓ ResultPath: $.Plan
BuildChunkList     (Pass state; expands ChunkCount into [0..N-1])
  ↓ Iterator.ChunkIndexes
Map state (MaxConcurrency=16)
  └── RenderChunk  (one Lambda invocation per chunk)
  ↓ Chunks[]
Assemble

Retry policy: 4 attempts, 2s initial, 2× backoff, max 60s — the policy spec'd in plan §9.4. Typed non-retryable error codes from §9.3 (FFMPEG_VERSION_MISMATCH, PLAN_HASH_MISMATCH, BROWSER_GPU_NOT_SOFTWARE, FONT_FETCH_FAILED, PLAN_TOO_LARGE, FORMAT_NOT_SUPPORTED_IN_DISTRIBUTED) are explicitly opted out of retry. The Map state's RenderChunk path picks the subset of non-retryables relevant to chunk workers.

Lambda function points at ../../packages/aws-lambda/dist/handler.zip via SAM's CodeUri local-path resolution. On sam deploy, the local ZIP is uploaded to SAM's managed staging bucket and CodeUri rewrites to that S3 URI. Override via the HandlerZipUri parameter for pre-uploaded ZIPs.

S3 bucket: Retain on stack delete; renders/ prefix expires after 7 days (plan tarballs + chunk outputs are intermediate); user-keepable artifacts go under a different prefix. Public access fully blocked.

CloudWatch alarm fires if RenderChunk invocations exceed ChunkInvocationAlarmThreshold per hour. The Map state's MaxConcurrency cap protects against simultaneous fan-out but not against a runaway state machine that loops; this alarm catches that.

Notable parameter knobs:

  • LambdaMemoryMb — 10 GB default; Lambda allocates CPU proportionally
  • LambdaTimeoutSec — 900s default (Lambda hard ceiling)
  • ReservedConcurrency — -1 (unreserved) by default; set to bound cost
  • ChromeSource — must match --source= passed to build-zip.ts

What's NOT in this PR (deferred to 6.3+):

  • A real-AWS deploy + benchmark workflow (PR 6.3)
  • CDK construct shipping the same topology (PR 6.4)
  • npx hyperframes lambda deploy CLI (PR 6.5)
  • Lambda RIE local smoke harness mode (PR 6.6)
  • Deployment docs page (PR 6.7) and migration guide (PR 6.8)

How is it tested

sam validate --lint against the template — passes:

/.../examples/aws-lambda/template.yaml is a valid SAM Template

Sample event payloads at examples/aws-lambda/sample-events/ cover all three handler actions and slot into sam local invoke RenderFunction --event <path> for local dispatch tests.

End-to-end real-AWS validation lands in PR 6.3 — that workflow does sam deploy → start state machine execution → assert PSNR ≥ 50 dB → sam delete against a HeyGen test AWS account.

Test plan

  • [x] sam validate --lint passes.
  • [x] YAML parses with CloudFormation intrinsic functions (!Ref, !Sub, !GetAtt, !If, !Not, !Equals, !Sub).
  • [x] All four state machine states (Plan, BuildChunkList, RenderChunks, Assemble) are reachable.
  • [x] Retry policies match plan §9.3 + §9.4.
  • [x] bunx oxlint + bunx oxfmt --check clean on the directory.
  • [ ] End-to-end deploy → render → teardown — lands in PR 6.3.

🤖 Generated with Claude Code

jrusso1020 avatar May 15 '26 23:05 jrusso1020

[!WARNING] This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite. Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

jrusso1020 avatar May 15 '26 23:05 jrusso1020