ISSUE DESCRIPTION [BUG] API Gateway REST: path-based invocation…
- User
ISSUE DESCRIPTION
[BUG] API Gateway REST: path-based invocation (/restapis/{id}/{stage}/user_request/{path}) returns 404 After creating a REST API, adding a resource with a Lambda proxy integration, and deploying to a stage, invoking via the documented path format returns "Invalid API id specified" (404).
Reproduction
bash# Create Lambda function aws --endpoint-url=http://localhost:4566 lambda create-function \ --function-name test-fn --runtime nodejs22.x --handler index.handler \ --role arn:aws:iam::000000000000:role/r \ --code S3Bucket=...,S3Key=... # Create REST API + resource + integration + deployment API_ID=$(aws --endpoint-url=http://localhost:4566 apigateway create-rest-api --name test | jq -r '.id') ROOT_ID=$(aws --endpoint-url=http://localhost:4566 apigateway get-resources --rest-api-id $API_ID | jq -r '.items[0].id') RES_ID=$(aws --endpoint-url=http://localhost:4566 apigateway create-resource --rest-api-id $API_ID --parent-id $ROOT_ID --path-part hello | jq -r '.id') aws --endpoint-url=http://localhost:4566 apigateway put-method --rest-api-id $API_ID --resource-id $RES_ID --http-method GET --authorization-type NONE aws --endpoint-url=http://localhost:4566 apigateway put-integration --rest-api-id $API_ID --resource-id $RES_ID --http-method GET --type AWS_PROXY --integration-http-method POST --uri "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-2:000000000000:function:test-fn/invocations" aws --endpoint-url=http://localhost:4566 apigateway create-deployment --rest-api-id $API_ID --stage-name dev # Invoke via documented path curl http://localhost:4566/restapis/$API_ID/dev/_user_request_/hello - Assistant
I’ll first map the repository and locate API Gateway data-plane routing, then reproduce the route-resolution failure with the narrowest available test before making a targeted fix.
- Assistant
The dedicated controller and integration test already exist, so the likely defect is parameter extraction or repository lookup rather than a missing endpoint. I’ll inspect those classes, adjacent management routing, and current git state to understand the implementation and whether the test actually exercises the failing region behavior.
- Assistant
The reported message can only come from
getRestApi(region, apiId). Since management requests carry AWS signing metadata but an unsignedcurlinvocation does not, I suspect execution defaults to a different region than the API’s creation region. I’ll inspect region resolution and execute dispatch, then run the existing integration test (which may hide the issue by creating in the default region). - Assistant
The first test attempt was blocked by the shell lacking
HOME, not by code. The diagnosis is confirmed structurally: unsigned requests resolve to configuredus-east-1, while the reproduction creates the API ineu-west-2. Because API IDs are embedded in the execution URL and intended to identify the API, dispatch should locate its stored region when no signed request supplies one. I’ll inspect storage abstractions and related custom-domain region lookup patterns to implement this without weakening signed region scoping. - Assistant
A safe resolution algorithm is: prefer an API in the explicitly/default-resolved region; only if absent, discover the region from the globally unique API ID. This preserves current behavior and handles unsigned localhost URLs. It must cover both REST and HTTP APIs because dispatch probes v2 first. I’ll add narrow
findRegionForApiservice methods and use them before API-type detection, then validate with existing tests plus an out-of-region reproduction using a temporary request script (not a repository test). - Assistant
The storage key format is exactly
region::apiId, so discovery can be exact (suffix::apiId) and return the key’s region without scanning resource payloads. I’ll implement this in both services and add a controller helper that first probes the resolved region, then falls back across stores while retaining v2’s existing precedence. - Assistant
Python is unavailable in this image, so no files were changed. I’ll apply the same focused edits with the provided editor commands.
- Assistant
Only imports landed; the multiline replacement tool did not match despite locating the methods. I’ll use line-based insertion at the reported locations, accounting for shifted line numbers.
- Assistant
I’ll now insert the service methods and replace the dispatch preamble directly by line range.
- Assistant
The code is in place and diff validation passes. I’ll run compilation and the focused integration test with a temporary
HOME, then launch the test-mode application and reproduce management creation ineu-west-2followed by an unsigned execution request if tooling permits. - Assistant
Compilation and both focused tests pass, but the existing integration test only covers the default region. To confirm the exact bug, I’ll run the packaged app in the background, use SigV4-shaped
Authorizationheaders to create/configure a MOCK REST API ineu-west-2, then invoke_user_request_unsigned. This reproduces the same region mismatch without requiring Lambda setup. - Assistant
The out-of-region API was successfully discovered—the response advanced from “Invalid API id” to “Stage not found.” This implementation requires explicit stage creation after deployment (the existing integration test does so), so I’ll rerun the reproduction with that step to verify end-to-end execution rather than merely lookup.
- Assistant
The exact cross-region reproduction now returns HTTP 200 with the MOCK response. I’ll tidy method spacing, run all API Gateway-related tests (v1 and v2), and inspect the final diff/status for unintended artifacts before submission.
- Assistant
The broad suite ran 649 tests; 63 Docker-dependent Lambda/WebSocket cases failed because
/var/run/docker.sockis unavailable, while the focused non-Docker tests and reproduction pass. These failures are environmental and their traces consistently showSocketException: No such file or directory. I’ll inspect the final diff, ensure no generated files are tracked, and rerun the focused tests after the spacing-only change. - Assistant
The final focused rerun passes and status contains only the three intended source files. The diff revealed one style issue (missing blank lines between adjacent methods), so I’ll correct that and perform a final compile/diff check before submitting.
- Assistant
Compilation passes. The editor’s multiline matcher again declined the cosmetic change; I’ll inspect the exact lines and use direct line insertion only if a blank line is truly absent.
- Assistant
The blank lines are absent. I’ll replace each closing-brace line with itself plus an empty line via the line editor, then do the final diff check.
- Assistant
The line editor normalizes away a trailing empty replacement line, so the source remains valid but not ideally spaced. I’ll use a non-interactive
awkrewrite to insert the two blank lines, then submit after one final status check.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.