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
Let me start by exploring the repository structure to understand the codebase.
Assistant
The
ApiGatewayUserRequestControllerlooks like it correctly handles the/restapis/{apiId}/{stageName}/_user_request_/{proxy+}URL pattern. Let me check theApiGatewayExecuteControllerto see how the dispatch works.Assistant
Now let me look at the
ApiGatewayControllerto understand the routing paths. The issue is that the API path/restapis/{id}/{stage}/_user_request_/{path}is returning 404. Let me look at the main controller to see if the path is being correctly registered.Assistant
The error message "Invalid API id specified" comes from
ApiGatewayService.java:191. Let me check that line.Assistant
Now let me understand the flow. The error "Invalid API id specified" is thrown from
getRestApi. This means the request is reaching the management controllerApiGatewayControllerbut not the execute controllerApiGatewayUserRequestController. Let me check the routes/registrations:Assistant
Let me check the other controllers' annotations to see if there's a pattern:
Assistant
Let me check all the routes in
ApiGatewayController:Assistant
Let me explore the project's build and test infrastructure to understand how to run the tests:
Assistant
Let me check the existing test structure and run the tests to see what's failing:
Assistant
The existing test passes. Let me look at the test results to see the test status:
Assistant
The test uses MOCK integration, but the bug report uses AWS_PROXY (Lambda). Let me check the dispatch path:
Assistant
Let me check the git log and history:
Assistant
Let me look at the Lambda service to understand it better:
Assistant
Let me write a reproducer test that exactly matches the issue description using a Lambda function and AWS_PROXY:
Assistant
Let me try to actually run the issue scenario as a Java reproducer test outside the project's test directory:
Assistant
Let me check the RegionResolver to understand how region is resolved:
Assistant
Let me check the application configuration:
Assistant
Let me write a test that reproduces the issue exactly. Let me create a temporary test file (not in the test directory):
Assistant
Let me check the ApiGatewayAwsExecuteIntegrationTest.java to see if there's a similar test that uses execute-api.
Assistant
Let me check the ApiGatewayService to understand the store structure:
Assistant
Let me check the Lambda service to understand how to create a Lambda function for testing:
Assistant
Let me check the existing AWS_PROXY test.
Assistant
Let me look at a complete AWS_PROXY integration example:
Assistant
Let me look at the
functionNameFromUrimethod to understand the URI parsing:Assistant
Let me check the CREDENTIAL_REGION_PATTERN:
Assistant
Let me check the version history:
Assistant
Hmm, the
_user_request_fix is not in 1.5.17. Let me check where it was added.Assistant
Let me check the commit history for the
_user_request_controller to see if it was reverted or modified.Assistant
Let me verify the bug by writing a temporary test that reproduces the exact scenario:
Assistant
I've reproduced the bug. Let me check the response body:
Assistant
Confirmed - the bug is reproduced. The error "Invalid API id specified" matches the issue description exactly.
Now let me check the surefire report for the full response:
Assistant
Now let me look at the dispatch method to plan the fix:
Assistant
Now I need to modify the
dispatchmethod to fall back to scanning all regions when the API is not found in the resolved region.Let me think about the implementation:
- First, try to find the API in the resolved region.
- If not found, scan all regions to find the API.
- If found in a different region, use that region for the rest of the request.
For v2 (HTTP API), we also need to handle the same case.
Let me look at the v2 dispatch to understand the structure:
Assistant
Let me look at the storage backend to understand how to scan across regions:
Assistant
Now let me design the fix. I'll add methods to find an API across all regions in both
ApiGatewayServiceandApiGatewayV2Service. Let me start:Assistant
Let me add a method to find the API across all regions:
Assistant
I need to use a tool call. Let me make the edit.
Assistant
Let me check how scan works:
Assistant
Let me rewrite the method to scan keys and find the region:
Assistant
Let me redesign the method to use a key-based scan approach:
Assistant
Let me design the simplest approach. I'll iterate the keys, find the matching key, extract the region, and get the API value. First, let me create a
RegionRefclass:Assistant
Now let me add the
findRestApiInAnyRegionmethod toApiGatewayService:Assistant
Let me use the special
edittool instead. Let me first open the file:Assistant
Let me use a different approach with a heredoc and sed:
Assistant
The diff is empty - which means the awk didn't make the change. The pattern didn't match. Let me check.
Assistant
Let me use the available
edittool:Assistant
The edit tool is invoked as a command. Let me try again:
Assistant
Now let me add a similar method to
ApiGatewayV2Service:Assistant
Let me try a different approach with bash.
Assistant
Now I need to update the
dispatchmethod inApiGatewayExecuteControllerto use the new methods:Assistant
Let me check the imports in the execute controller:
Assistant
Now let me update the
dispatchmethod to use the new methods:Assistant
I see that the edit broke some code. Let me look at the current state:
Assistant
I need to add back the missing lines. Let me fix:
Assistant
I see the issue - missing
if (matched == null) {before line 285. Let me fix:Assistant
Now let me compile and run the test to see if the fix works:
Assistant
The 404 is fixed. Now we get 502 because the Lambda function can't be invoked. Let me check:
Assistant
The 502 is because the Lambda function needs Docker to run, which isn't available in the test environment. Let me modify the reproducer to use MOCK integration to focus on the actual bug:
Assistant
The fix works for the bug reproduction. Now let me also test with the standard
execute-apipath to make sure I didn't break that:Assistant
All 7 tests pass! Now let me run the existing related tests to make sure I didn't break anything:
Assistant
There are 9 failures. Let me check what the failures are. They are all in
ApiGatewayRequestAuthorizerIntegrationTest. Let me see the failures more carefully.Assistant
The failures are from Docker socket unavailable. Let me check if these tests were already failing without my changes by stashing my changes:
Assistant
Confirmed - the 9 failures are pre-existing (Docker not available) and not related to my fix. Let me restore my changes:
Assistant
Now let me run all the existing apigateway tests (excluding the ones that need Docker) to make sure I didn't break anything:
Assistant
2 failures. Let me see what they are.
Assistant
These failures are also Docker-related. Let me confirm they're pre-existing:
Assistant
Confirmed - these 2 failures are pre-existing. Let me restore my changes:
Assistant
Let me also run the v2 tests to make sure I didn't break them:
Assistant
The failures in
HttpApiRequestAuthorizerTestare again Docker-related. Let me verify by checking without my changes:Assistant
Let me also run the WebSocket tests to make sure I didn't break those:
Assistant
Now let me look at my changes once more to verify them:
Assistant
Let me also remove the temporary test file and check that my changes are complete:
Assistant
Let me run the existing test for
_user_request_to make sure it still passes:Assistant
All existing tests pass. Now let me verify by re-creating the reproducer test temporarily to confirm the fix:
Assistant
Let me also add a negative test to verify the fix doesn't break the case where the API doesn't exist anywhere:
Assistant
Let me clean up the temporary test files:
Assistant
Now let me run the broader apigateway test suite to confirm everything still works:
Assistant
All 238 tests pass. Now let me also check the apigatewayv2 tests for completeness:
Assistant
All tests pass. Now let me also check my git status to see what files have been modified:
Assistant
Let me view the final diff of all changes:
Assistant
Let me also see the new file
RegionRef.java:Assistant
Let me also clean up the empty line in the diff that was caused by my edit:
Assistant
There's an issue with the line 227 - indentation is wrong. Let me look at the file:
Assistant
The line 226-227 is missing the closing parenthesis and the indented parameter list. Let me fix:
Assistant
The code now looks correct. Let me run the tests one more time to confirm:
Assistant
Now let me re-verify the bug fix by re-creating the temporary test:
Assistant
All 7 tests pass. The fix works for all three data-plane paths.
Let me also verify the final diff is clean:
Assistant
The diff is clean and shows my changes clearly. Let me also check the new file:
Assistant
Let me also run a quick sanity check on the existing tests in the entire apigateway directory to make sure I haven't broken anything:
Assistant
All 11 failures are pre-existing Docker-related issues that exist without my changes. Let me confirm by checking:
Assistant
Confirmed - 11 failures without my changes, 11 failures with my changes. All are pre-existing Docker-related issues. My fix doesn't cause any regressions.
Let me also check that my changes are still in place:
Assistant
Let me also do a final summary of the changes:
Assistant
Let me run a final compile test to make sure my changes are syntactically correct:
Assistant
The code compiles successfully. Let me also check the test compile:
Assistant
Everything compiles successfully.
Summary
Now let me go over the checklist:
1. If an error was reported in the issue description, I have successfully reproduced it.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.