Skip to content

feat(cloud): host the fleet gateway on AWS Lambda - #301

Merged
outofcoffee merged 14 commits into
mainfrom
feat/lambda-gateway-hosting
Nov 30, 2026
Merged

outofcoffee merged 14 commits into
mainfrom
feat/lambda-gateway-hosting

Conversation

@outofcoffee

Copy link
Copy Markdown
Collaborator

Serve the fleet gateway on AWS Lambda behind a Lambda Function URL — the same handler, the same paths and the same bearer-token gate as the foreground gateway, with no long-lived host.

Summary

  • spinloop cloud gateway deploy stages the function ZIP (the gateway binary, the fleet file and every Spinloop source the file names, baked under /var/task/config/), drives the gateway stack's deploy through the same version-matched-sources machinery as bootstrap, and prints the Function URL to name in the fleet file's gateway section.
  • spinloop cloud gateway destroy removes the gateway stack and nothing else; it is a no-op when the stack is absent.
  • The gateway self-detects the Lambda runtime (SPINLOOP_LAMBDA=1) and serves the handler through the AWS Lambda adapter — the same internal/gateway, no forked logic. The fleet file defaults to /var/task/config/fleet.yaml (or SPINLOOP_FLEET_PATH).
  • The stack (cloud-vm-llm-gateway) is a custom-runtime Lambda (ARM_64, 900 s) behind a Function URL (RESPONSE_STREAM, auth NONE — the gateway's own bearer token is the only caller gate), with a role scoped to the control-plane start and stats functions plus stack discovery, and a bounded-retention log group.
  • The ZIP never carries a secret: the caller token is set on the function at deploy time (--api-token or SPINLOOP_API_TOKEN), the fleet file baked in names environment variables, and every node/engine token resolves from the function's environment at invocation time.

Closes #298

Implementation details

  • The deploy requires the control-plane stack to exist first (the gateway stack imports its outputs for the start and stats functions) and fails fast naming bootstrap as the fix.
  • Alias-sourced nodes are refused at deploy time — the alias registry is machine-local and cannot ride in the ZIP — with a message naming the node and the fix (a file: field or a subdirectory beside the fleet file).
  • Sources outside the fleet file's directory are refused too: the ZIP can only carry sources beside the fleet file.
  • The binary comes from the release's own artifact for a clean release version (spinloop_linux_arm64.tar.gz from the matching GitHub release), or a go build from the source tree for a dev build.

@outofcoffee outofcoffee added enhancement New feature or request go Pull requests that update go code labels Nov 28, 2026
@outofcoffee
outofcoffee force-pushed the feat/lambda-gateway-hosting branch from e7fa15b to 9638651 Compare November 28, 2026 23:03
Adds `spinloop cloud gateway deploy/destroy`: deploy stages the function ZIP (the gateway binary, the fleet file and every Spinloop source the file names, under /var/task/config/), drives the gateway stack's deploy through the same version-matched-sources machinery as bootstrap, and prints the Function URL; destroy removes the stack and nothing else. The gateway serves the same handler in Lambda mode (SPINLOOP_LAMBDA=1, the fleet file baked at /var/task/config/fleet.yaml) behind a Function URL with the gateway's own bearer token as the only caller gate — no secret in the ZIP, the caller token set on the function at deploy time.
…tack

The gateway stack imports StartFnArn, StatsFnArn and StackArn from the control-plane stack via Fn::ImportValue, but the outputs carried no export name — CloudFormation refuses the import and the gateway stack rolls back at creation. Export all three with the names the gateway imports, and assert the exports in the stack test.
…missing the ARN outputs

The gateway stack imports StartFnArn, StatsFnArn and StackArn from the control-plane stack; a plane deployed before this change exports none of them, so the stack failed creation and rolled back at the cdk step. Read the control plane's outputs before building the ZIP and fail with the fix named — re-run spinloop cloud bootstrap — instead.
update-function-configuration replaces the whole Variables map, so the documented command would have wiped SPINLOOP_LAMBDA and SPINLOOP_API_TOKEN along with the token it added. Document the replace semantics, show the merged map, and name how to find the function.
…mmand

The Lambda runtime invokes the binary with no arguments and no command name, so the gateway subcommand never ran and the binary printed the help text and exited non-zero in init. Detect SPINLOOP_LAMBDA=1 in run(), before the command tree is built, and dispatch to the Lambda gateway. Adds a test asserting the dispatch returns the handler's error rather than the help text.
@outofcoffee
outofcoffee force-pushed the feat/lambda-gateway-hosting branch from 57e2c40 to 174f0d0 Compare November 29, 2026 00:20
The gateway's function runs VPC-attached to the control plane's own VPC
(public subnets, the same shape the engines launch into) with its own
security group — outbound only — recorded in the well-known SSM parameter
/cloud-vm-llm/gateway/security-group-id. The environment deploy's
ingress reconciliation admits the gateway's security group alongside the
deploying machine's CIDR, so the gateway reaches every deployed cloud node
regardless of whether the node has an SG entry for the deploying machine.
The engines' ingress is never widened to 0.0.0.0/0.
AWS rejects non-ASCII characters in a security group description; the em
dash in the gateway's description failed the stack deploy.
IpPermission has no SourceSecurityGroupId field — the SDK silently dropped
it, so the reconcile authorized a sourceless rule and the SG kept only the
CIDR. Both sources now ride in one rule, the shape AWS produces.
…-plane VPC

The Lambda hosting subcommands move from `cloud gateway` to `spinloop
gateway` (deploy, show, destroy): the gateway is a serving mode of the
foreground command, so its hosting lives under the same name. The deploy now
passes the control plane's private subnets and the stated plane URLs to the
stack; show prints the deployed gateway's URL and diagnostics, read live.
The gateway's function runs in the control plane's private subnets routed
through the NAT gateway and reaches engines at their VPC-private IP, so the
start Lambda reports the instance's private_ip and the gateway swaps to the
private address on the engines' own network.
Sync the delta spec into the new main spec openspec/specs/lambda-gateway-hosting/spec.md (purpose plus eight requirements, every scenario intact) and archive the change under openspec/changes/archive/2026-11-30-lambda-gateway-hosting/.
@outofcoffee
outofcoffee marked this pull request as ready for review November 30, 2026 02:25
@outofcoffee
outofcoffee merged commit 780b43b into main Nov 30, 2026
6 checks passed
@outofcoffee
outofcoffee deleted the feat/lambda-gateway-hosting branch November 30, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: lambda hosting of gateway

1 participant