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 explore the repository structure first.
Assistant
Let me look at the middle part of the dispatch method that was truncated.
Assistant
Now I understand the dispatch. The
getRestApiis called withregion. The issue is the 404 "Invalid API id specified". Let me look atgetRestApiand how region resolution works.The issue is path-based invocation via
/restapis/{apiId}/{stageName}/_user_request_/{path}. Let me look at theApiGatewayService.getRestApiandgetStage.Assistant
So
getRestApilooks up byapiKey(region, apiId). If the region doesn't match the region where the API was created, it returns 404.The issue: The data plane invocation via
/restapis/...path doesn't pass the correct region. Let me look atresolveRegionto understand what region is resolved from headers.Let me check the RegionResolver.
Assistant
So
resolveRegionreturns the region from the Authorization header, ordefaultRegionif none. For the curl invocationcurl http://localhost:4566/restapis/$API_ID/dev/_user_request_/hello, there is no Authorization header, so it returns the default region.The reproduction creates the API via the management plane with region
eu-west-2. So the API is stored keyed byeu-west-2. But the data plane curl request has no Authorization header, soresolveRegionreturns the default region. If the default region differs fromeu-west-2, the lookup fails with 404.Let me check the default region.
Assistant
Confirmed: default region is
us-east-1. The issue is: when invoking via/restapis/...path (data plane) without an Authorization header,resolveRegionreturnsus-east-1, but the API was created ineu-west-2, sogetRestApi("us-east-1", apiId)returns 404.Let me look at how the API store works and whether there's an "all regions" scan.
Assistant
The API is keyed by
region::apiId. Data plane requests without an auth header resolve to the default region, which doesn't match the region where the API was created. Let me check the RestApi model to see if it stores its own region.Assistant
RestApi doesn't store its own region. I need to scan the apiStore to find the matching apiId and figure out the region from the key. Let me check the StorageBackend interface.
Assistant
Now let me look at how the v2 path is checked, and whether v2 APIs have a similar region-keying issue.
Assistant
Let me view the exact dispatch method region handling block to edit it precisely.
Assistant
Now let me add a
findApiRegionmethod to ApiGatewayService.Assistant
Let me use the edit tool instead.
Assistant
I introduced a duplicate line. Let me fix that.
Assistant
Now the service looks good. Now let me modify the dispatch method in ApiGatewayExecuteController to fall back to cross-region lookup.
Assistant
Now I'll modify the dispatch method to fall back to a cross-region lookup when the resolved region doesn't match.
Assistant
Now let me build to verify compilation.
Assistant
Compilation succeeded (only warnings). Let me confirm there were no errors.
Assistant
Build succeeds. Now let me look at existing tests for the apigateway execute controller to understand the test setup and conventions, so I can create a reproduction test.
Assistant
This existing test uses the default region for both creation and invocation, so it doesn't reproduce the cross-region issue. The issue's reproduction uses the AWS CLI which sends an Authorization header with region
eu-west-2. Let me check how tests pass an Authorization header.Assistant
Those Authorization headers are bearer tokens for authorizers, not AWS SigV4 credentials. Let me find how a SigV4-style Authorization header is constructed in tests. Let me search for "Credential" in tests.
Assistant
I'll create a temporary reproduction test (which I'll remove before submitting). Let me first check the existing unit test to understand the test approach.
Assistant
Let me create a temporary integration test that creates an API in a non-default region (via Authorization header) and invokes via
_user_request_without an Authorization header.Assistant
Let me run the reproduction test with my fix in place to confirm it passes.
Assistant
Offline mode is missing the surefire provider. Let me try without offline mode to allow downloads.
Assistant
The test ran and the API was created in eu-west-2. Let me check the explicit test result.
Assistant
All 6 tests pass with my fix. Now let me confirm the bug actually existed before the fix by temporarily reverting and re-running.
Assistant
Confirmed: without the fix, the test fails with "Invalid API id specified" (404). With the fix, it passes. Now let me remove the temporary test file and run the existing related tests to ensure nothing breaks.
Assistant
Now let me run the existing related apigateway integration tests to ensure nothing breaks.
Assistant
All passing. Let me run the broader apigateway test suite to be safe.
Assistant
Hmm, exit code 0 but earlier said BUILD FAILURE. The grep filter hid it. Let me run with full output to a file and inspect.
Assistant
The glob pattern didn't match. Let me run with a simpler pattern.
Assistant
There are failures in authorizer tests. I need to determine whether these are pre-existing or caused by my change. Let me check against the original code.
Assistant
The same 11 failures occur on the original unmodified code — they are pre-existing and NOT caused by my change (identical failure counts: 2 + 9 = 11 in both cases). My change introduces no regressions.
Let me review the final diff.
Assistant
The fix is focused and correct. Let me verify the final git status shows only the two source files modified (no leftover temp test).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.