Skip to content

Fix 404s from API Gateway stage prefix on Lambda - #2

Merged
peniakoff merged 1 commit into
mainfrom
cursor/strip-apigw-stage-prefix-13a9
Aug 18, 2026
Merged

Fix 404s from API Gateway stage prefix on Lambda#2
peniakoff merged 1 commit into
mainfrom
cursor/strip-apigw-stage-prefix-13a9

Conversation

@peniakoff

@peniakoff peniakoff commented Aug 18, 2026

Copy link
Copy Markdown
Owner

HTTP API with StageName: prod forwards /prod/healthz and /prod/v1/feedback to Lambda. httpadapter.NewV2 keeps that raw path, and Go 1.22 ServeMux matches /healthz and /v1/feedback exactly, so both routes returned plaintext 404 page not found (Weles headers) even though API Gateway had the routes.

Change

  • Lambda wraps the mux with StripStagePrefix using WELLS_API_STAGE from SAM StageName.
  • /prod is removed as a path segment before routing. $default and empty stage are no-ops; unprefixed /healthz still works.
  • Public execute-api URLs stay {ApiEndpoint}/healthz and {ApiEndpoint}/v1/feedback.

/healthz vs /health

Left as /healthz. That is the documented OpenAPI/Docker liveness path (Kubernetes-style), and changing it would be a breaking rename that would not fix the 404. The bug is the stage prefix, not the probe name.

Test plan

  • GET /prod/healthz and POST /prod/v1/feedback succeed with the strip middleware
  • Unprefixed /healthz still succeeds (Docker / $default)
  • /production/healthz is not treated as stage prod
  • go vet, go test -race, server and Lambda builds locally
  • After deploy: GET https://{api-id}.execute-api.eu-central-1.amazonaws.com/prod/healthz returns {"status":"ok"}
Open in Web Open in Cursor 

HTTP API named stages pass /prod/healthz into httpadapter.NewV2, and Go 1.22 ServeMux matches paths exactly. Strip WELLS_API_STAGE (from SAM StageName) before the mux so /healthz and /v1/feedback work on the execute-api URL.

Co-authored-by: Tomasz Miller <peniakoff@users.noreply.github.com>
@peniakoff
peniakoff marked this pull request as ready for review August 18, 2026 15:49
@peniakoff
peniakoff merged commit ca9f0ad into main Aug 18, 2026
4 checks passed
@peniakoff
peniakoff deleted the cursor/strip-apigw-stage-prefix-13a9 branch August 18, 2026 15:51
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.

2 participants