Fix 404s from API Gateway stage prefix on Lambda - #2
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTTP API with
StageName: prodforwards/prod/healthzand/prod/v1/feedbackto Lambda.httpadapter.NewV2keeps that raw path, and Go 1.22 ServeMux matches/healthzand/v1/feedbackexactly, so both routes returned plaintext404 page not found(Weles headers) even though API Gateway had the routes.Change
StripStagePrefixusingWELLS_API_STAGEfrom SAMStageName./prodis removed as a path segment before routing.$defaultand empty stage are no-ops; unprefixed/healthzstill works.{ApiEndpoint}/healthzand{ApiEndpoint}/v1/feedback./healthzvs/healthLeft 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/healthzandPOST /prod/v1/feedbacksucceed with the strip middleware/healthzstill succeeds (Docker /$default)/production/healthzis not treated as stageprodgo vet,go test -race, server and Lambda builds locallyGET https://{api-id}.execute-api.eu-central-1.amazonaws.com/prod/healthzreturns{"status":"ok"}