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
# 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_/helloActual behavior
HTTP 404:
{"message":"Invalid API id specified"}Expected behavior
Request routes through API Gateway to the Lambda function and returns the Lambda response.
Notes
- The API is created successfully (confirmed via get-rest-api and Floci logs)
- The deployment succeeds
- Management plane operations (create/get/update APIs) all work correctly
- Only the data plane invocation path fails
- Tested with Floci 1.5.16
Environment
- Floci 1.5.16 (docker.io/floci/floci:latest)
- Podman 5.8.0 rootless (also likely reproducible with Docker)
- AWS CLI v2
- Region: eu-west-2
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /floci, current file: none) bash-$
Assistant
Let me explore the repository structure to understand what we're working with.
Assistant
This is a Java project (Maven). Let me explore the source structure and find the API Gateway related code.
Assistant
Let me look at the routing. There's likely a conflict because the management plane ApiGatewayController also uses
/restapispath. Let me check.Assistant
The management plane controller has paths like
/restapis/{apiId}etc. The user request controller has/restapis/{apiId}/{stageName}/_user_request_.The issue is "Invalid API id specified" 404. Let me look at the ApiGatewayController for the
@Path("/restapis/{apiId}")GET to see where "Invalid API id specified" comes from.Assistant
Now let me look at the ApiGatewayExecuteController to understand the dispatch method and how the apiId is being resolved. The issue says invoking via
/restapis/$API_ID/dev/_user_request_/helloreturns 404 "Invalid API id specified".The user request controller calls
executeController.dispatch("GET", apiId, stageName, proxy, ...). Let me look at the dispatch method.Assistant
The "Invalid API id specified" comes from
getRestApi, called bydispatch. So dispatch IS being reached butgetRestApi(region, apiId)fails. Let me look atRegionResolverto understand region resolution.Assistant
So
resolveRegionresolves the region from the Authorization header (Credential=AKID/date/region/...). When you use curl directly, there's no Authorization header, so it returns the default region.If the API was created in
eu-west-2but the default region isus-east-1, then the getRestApi would fail with "Invalid API id specified".But wait, the issue says this is reproducible. Let me think about whether this is the actual root cause. The issue title says path-based invocation returns 404. Let me actually try to reproduce. But first, let me understand how the management plane resolves region.
Actually, the AWS CLI sends the Authorization header with the region. So management plane operations use the correct region
eu-west-2. But curl without auth uses the default region.However, this is a behavior issue. In LocalStack, the API Gateway invocation works regardless of region because LocalStack uses a single global store or resolves region from the API id. Actually, the API id is globally unique in LocalStack.
Hmm. But let me think about the actual issue. The issue is path-based invocation. Let me check whether the routing actually reaches the UserRequestController.
Actually, let me first reproduce the issue by building and running. Let me check the test directory for existing tests around this.
Assistant
This test uses the default region (no Authorization header), so both create and execute use the default region and it works. The issue arises when the API is created in a non-default region (
eu-west-2) via AWS CLI (which sends the Authorization header with the region), but the curl invocation has no auth header, so it resolves to the default region. Let me verify by looking at the dispatch logic more and the v1 store keys.Assistant
Confirmed. The API is region-scoped. The data plane invocation with curl (no auth) resolves to the default region, so it doesn't find the API created in
eu-west-2. Let me check the default region config.Assistant
Default region is
us-east-1. So an API created ineu-west-2and invoked via curl (no auth) resolves tous-east-1→ not found → 404. Let me check theStorageBackendinterface to see what scan/lookup methods are available.Assistant
There's
scan(Predicate<K>)returning values andkeys()returning keys. Let me check the v2 servicegetApiand how the execute-api dispatch uses the region downstream, plus howdispatchV2resolves region.Assistant
Now let me look at the full dispatch method and the dispatchV2 to understand how region is used downstream, so I can design the fix consistently.
Assistant
Let me check the
RestApimodel to see if it stores the region.Assistant
Now I understand the root cause. The data plane dispatch resolves the region from the Authorization header. A
curlrequest without auth resolves to the default region (us-east-1), but the API was created ineu-west-2(via AWS CLI which sends the region in the auth header). Since API ids are unique across the emulator, the fix is to fall back to a global lookup by apiId when the API isn't found in the resolved region.Let me check the v2 service's apiKey helper and store field name.
Assistant
Let me look at how tests set the region (e.g. via Authorization header) so I can write a reproduction.
Assistant
Those Authorization headers are for the authorizer (Bearer tokens), not for AWS SigV4 region. Let me check how the region is determined in the management plane. Let me look at how the CLI sends region. Actually, let me look at how the management controller resolves region - it uses a similar regionResolver.
Let me look at how a test creates an API in a specific region. Let me search for tests that set a region header.
Assistant
Let me look at how the management controller resolves region for create operations.
Assistant
So the management plane resolves the region from the Authorization header (Credential region). The AWS CLI sends the region, so the API is stored in
eu-west-2. Acurlwithout auth resolves to the defaultus-east-1, hence the 404.Let me look at
dispatchV2to understand if it re-resolves region internally.Assistant
dispatchV2uses the region passed in. So fixing region resolution before calling it is sufficient. Now let me implement the fix. First, add a helper method toApiGatewayService.Assistant
Now let me add the helper method to
ApiGatewayService:Assistant
Now let me add the analogous helper to
ApiGatewayV2Service:Assistant
Now let me modify the
dispatchmethod inApiGatewayExecuteControllerto use the global fallback:Assistant
Now let me rewrite the dispatch method's region resolution to add the global fallback:
Assistant
Now let me build to verify compilation and run the existing related tests.
Assistant
Compilation succeeded. Now let me create a temporary reproduction test (I'll remove it before submitting) that creates an API in a non-default region via an Authorization header and invokes via
_user_request_without auth.Assistant
Now let me run the temporary test plus the existing user request test to confirm the fix works and nothing breaks.
Assistant
Offline mode is missing the surefire platform jar. Let me try online mode to download the needed test runner.
Assistant
The tests ran and completed. Let me confirm the test results from the surefire reports.
Assistant
Both tests pass with the fix. Now let me verify the bug actually existed before the fix by temporarily reverting only the controller change.
Assistant
Now let me run the temp test against the original (unfixed) controller to confirm the bug reproduces.
Assistant
Confirmed: the bug reproduces without the fix — both
_user_request_andexecute-apipaths return 404 "Invalid API id specified". Now let me restore the fix.Assistant
Now let me run the broader set of API Gateway tests to ensure nothing is broken by the change.
Assistant
There are failures in authorizer tests involving Lambda invocations (Docker socket errors). Let me verify these are pre-existing environmental failures by reverting all my changes and running those same tests.
Assistant
Confirmed — that test fails on the original code too (pre-existing environmental failure due to Docker/Lambda not being available). Not caused by my change. Let me restore my fix.
Assistant
My fix is restored. Let me run the non-Lambda-dependent API Gateway tests to confirm they pass with my change.
Assistant
All non-Lambda tests pass. Let me also run the apigatewayv2 tests to ensure the v2 service change doesn't break anything.
Assistant
WebSocketConnectionsApiTest has 5 errors. Let me check whether these are pre-existing by running them on the original code.
Assistant
These WebSocket errors are due to Docker not being available (unix socket). Let me confirm they're pre-existing by running on the original code.
Assistant
Confirmed — the same 5 errors exist on the original code (Docker socket unavailable). These are pre-existing environmental failures, not caused by my change.
Now let me remove the temporary test file before submitting.
Assistant
Let me review the final diff of my changes.
Assistant
The changes look correct. Let me do a final compile check to be safe.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →