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
This is a Java project (Maven). Let me explore the source structure, particularly around API Gateway.
Assistant
The relevant file for the data plane invocation path is
ApiGatewayUserRequestController.java. The path format is/restapis/{id}/{stage}/_user_request_/{path}. Let me look at this file.Assistant
This controller exists. But the issue says invoking
/restapis/$API_ID/dev/_user_request_/helloreturns 404 "Invalid API id specified". Let me look at theApiGatewayController.java- that handles management operations likecreate-rest-api,get-resources, etc. These management endpoints are at/restapistoo. There's a conflict.Wait. The management API for API Gateway uses
/restapistoo. Let me look at the ApiGatewayController path annotations.Assistant
Now let me look at the
ApiGatewayExecuteController.java- thedispatchmethod.Assistant
So the dispatch resolves region from headers, and then calls
getRestApi(region, apiId). The error "Invalid API id specified" is returned when the API is not found in that region. The issue is likely with region resolution when invoked via/restapis/.../_user_request_/....Let me look at the RegionResolver to understand how region is resolved. The issue says region eu-west-2 is used. The management plane operations work (create/get/update APIs) - those would use the region from headers. But the data plane invocation fails.
Let me look at the RegionResolver.
Assistant
When invoking via plain curl (no auth header), the region resolves to the default region. The management plane stores the API under the region from the AWS CLI's Authorization header (eu-west-2). The data plane invocation via plain curl has no Authorization header, so it resolves to defaultRegion. Let me check the default region.
Assistant
So the default region is
us-east-1. The API was created in eu-west-2 (because the AWS CLI region is eu-west-2). When invoking via plain curl with no Authorization header, the region resolves tous-east-1, sogetRestApi("us-east-1", apiId)fails with "Invalid API id specified".This is the bug! The data plane invocation should be able to find the API regardless of region, OR the region should be derived differently.
In real AWS, the API Gateway data plane invocation is region-scoped via the URL (
{apiId}.execute-api.{region}.amazonaws.com). With LocalStack-style endpoint/restapis/{apiId}/{stage}/_user_request_/{path}, there's no region in the URL. So LocalStack typically ignores region for the data plane and searches all regions, or uses a single global store.Let me think about how LocalStack handles this. In LocalStack, the API is looked up across regions. Actually LocalStack has a single-region model usually. But Floci supports multi-region via the region store.
The right fix here: when the API is not found in the resolved region (because there's no auth header to determine region), the data plane dispatch should search across all regions. Let me look at how getRestApi works and whether there's a method to find an API by id across regions.
Assistant
Let me check the execute-api controller and whether region is resolved from the host. Let me search for "Host" header parsing.
Assistant
No host-based region parsing. Both execute-api and user_request endpoints resolve region from the auth header, defaulting to us-east-1. When the API is created in a non-default region (eu-west-2), invoking via curl (no auth) resolves to us-east-1 and fails.
Let me look at the ApiGatewayService stores and how they're keyed.
Assistant
Now let me look at the apiKey helper method and getRestApis (which scans all regions). Let me find apiKey and how keys are structured.
Assistant
Now I understand the structure. Let me look at the StorageBackend interface to understand what scanning capabilities exist.
Assistant
Let me look at the full dispatch method and the imports in ApiGatewayExecuteController.
Assistant
Now let me look at the dispatch method more fully and also dispatchV2's region usage to understand whether changing region is safe. Let me see the full dispatch through to where resources/stage/integration are looked up.
Assistant
Let me look at the ApiGatewayV2Service key helpers and imports.
Assistant
Let me check the existing tests for the user request controller to understand the testing approach and avoid breaking them.
Assistant
This existing test uses the default region (us-east-1) since the management calls don't include an Authorization header (RestAssured). Let me confirm how region is resolved for management calls.
Assistant
Let me check which controller handles the
/restapismanagement calls and how region is resolved there.Assistant
Let me build the project and run the existing user request test to confirm routing works when regions match.
Assistant
The existing test passes (both management and data plane use us-east-1). Now let me write a temporary reproduction test that mimics the issue: create the API in eu-west-2 by adding an Authorization header, then invoke via user_request WITHOUT auth.
Assistant
Reproduced the bug (404). Now let me implement the fix. First, let me check imports in both services for
Optional.Assistant
Neither has Optional imported. Let me add the import and the helper methods. First,
ApiGatewayService:Assistant
Now add the helper method to
ApiGatewayServiceright aftergetRestApi:Assistant
No python. Let me use the
editcommand. Let me open the file and view the relevant lines.Assistant
The edit created a duplicate
getRestApimethod. Let me fix that.Assistant
ApiGatewayService is fixed. Now let me add the same helper to
ApiGatewayV2Service.Assistant
Now let me modify the
dispatchmethod inApiGatewayExecuteController. First, add theOptionalimport.Assistant
Now let me modify the
dispatchmethod:Assistant
Now let me replace the dispatch region-resolution logic:
Assistant
Now let me compile and run the reproduction test.
Assistant
The reproduction test now passes. Let me run the broader API Gateway test suite to ensure no regressions.
Assistant
There are failures in authorizer tests. Let me check whether these failures are pre-existing or introduced by my change. Let me stash my changes and run those tests on the original code.
Assistant
These 11 failures are pre-existing on the original code (before my change) — the same 11 failures. So my change did not introduce regressions. Let me restore my changes.
Assistant
The pre-existing authorizer test failures occur identically with and without my change, confirming they're unrelated. Let me verify the failure reason is environmental (Lambda runtime) and not related to region routing.
Assistant
Let me look at this authorizer test — its 404 failure might be the same cross-region bug. Let me examine the test setup.
Assistant
This test uses REGION = us-east-1 (the default), and creates APIs without auth header (so they're stored in us-east-1). The execute-api invocations also use RestAssured without auth header → resolves to us-east-1. So region matches. The 404 must be something else — likely the Lambda invocation failing because there's no Node.js runtime available in this test environment. Let me check
preservation_noneAuthorizerSkipsInvocationline 496 to confirm.Actually wait — the failure is "Expected 200 but was 404". A 404 could mean the resource/method isn't matched, or the integration returned 404. But this is pre-existing on original code. It's an environmental issue (Lambda runtime not available). Not related to my fix.
Let me confirm by looking at the test method at line 496.
Assistant
The 404 in these authorizer tests is from Lambda invocation failures (no Node.js runtime in this environment) — pre-existing and unrelated. My change produced the exact same 11 failures as the original code (no new regressions).
Let me run the directly-related tests to confirm they pass with my change.
Assistant
All directly-related tests pass. Let me also run the v2 execute tests to confirm no regression in the v2 path.
Assistant
All v2 tests pass. Let me check the custom domain filter, which might be another data-plane entry point with the same region issue.
Assistant
The custom domain filter rewrites to
/execute-api/...which goes through dispatch, so it benefits from my fix. Let me check whether the custom domain lookup methods themselves are region-scoped (potential similar bug).Assistant
The custom domain lookups are already region-agnostic. My fix makes the execute-api dispatch consistent. Let me review the final diff.
Assistant
Let me fix the import ordering in the v2 service for cleanliness (Optional should come after Map alphabetically).
Assistant
Let me do a final compile and run the full API Gateway suite once more to confirm no new regressions.
Assistant
The hashes differ. Let me compare the actual set of failing test method names between original and modified to ensure there are no new failures.
Assistant
The failing tests are IDENTICAL between original and modified — the exact same 11 pre-existing authorizer tests (which fail due to the Lambda/Node runtime not being available in this environment, not due to my change). My change introduces no new regressions.
Let me do a final clean compile to ensure everything compiles.
Assistant
Compilation succeeds. Let me confirm the temporary reproduction test is removed and check git status.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.