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 using command. Additionally, you can use and to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
Let me explore the repository structure to understand what we're working with.
Assistant
This is a Java project. Let me explore the source structure.
Assistant
Let me look at the routing. The issue is about the
/restapis/{apiId}/{stageName}/_user_request_/{proxy+}path returning 404. Let me check how the routing might conflict with other paths in ApiGatewayController. There might be a route like/restapis/{apiId}that's catching the request before the UserRequestController.Let me search for paths matching
/restapis/{apiId}in the controllers.Assistant
Let me look at the ExecuteController and the dispatch method to find where "Invalid API id specified" comes from.
Assistant
The error message "Invalid API id specified" - let me search for that message.
Assistant
So the error message comes from
getRestApi. The issue says the API is created successfully and management operations work. But invocation via the user request path fails with "Invalid API id specified". Let me think...The path is
/restapis/{apiId}/{stageName}/_user_request_/{proxy+}. But there's also a route in ApiGatewayController at (DELETE, etc.) and other paths like .Assistant
So when invoking
curl http://localhost:4566/restapis/$API_ID/dev/_user_request_/hello, there's no Authorization header (curl without AWS sig). So region resolves to defaultRegion. But the API was created with region eu-west-2 (from the AWS CLI's Authorization header). So the data plane invocation via curl has no Authorization header, resolving to defaultRegion, sogetRestApi(defaultRegion, apiId)fails.Let me verify by checking how storage works and whether APIs are stored per-region.
Assistant
APIs are stored per-region. The API was created with region eu-west-2 (from AWS CLI Authorization header). The data plane curl invocation has no Authorization header, so region resolves to defaultRegion. If defaultRegion != eu-west-2, then getRestApi fails.
Let me check the existing tests to understand expected behavior.
Assistant
The existing test creates the API without an Authorization header (RestAssured default), so region = defaultRegion, and invokes also without auth — both use defaultRegion, so it works. In the issue, the AWS CLI creates the API with region eu-west-2 (from the credential in the Authorization header), but the curl invocation has no auth → defaultRegion → mismatch → 404.
Let me confirm the default region config and look at how storage keys are formed.
Assistant
Default region is us-east-1. The reproduction creates under eu-west-2 but invokes under us-east-1 (curl without auth) → 404. Let me look at the dispatch method in detail.
Assistant
Now I understand the root cause. The
dispatchresolves region from the Authorization header. When there's no auth header (curl), it falls back to defaultRegion (us-east-1), but the API was created under eu-west-2. Let me look at the storage layer to find a way to scan across regions by apiId.Assistant
Now let me look at the StorageBackend interface to understand what operations are available (scan, keys, etc.).
Assistant
Now I understand the storage. Let me see all references to
regionin the dispatch method to plan the fix.Assistant
The cleanest fix: at the top of
dispatch, after resolving the region from the auth header, determine the actual region where the API lives. API ids are globally unique within the emulator, so if the API isn't found in the resolved region, search across all regions. Let me look at the v2 service's getApi and store.Assistant
Now I'll add cross-region lookup helper methods to both services. Let me add them near the apiKey helper methods.
Assistant
Now add the helper methods. Let me add
findRegionForRestApito ApiGatewayService right aftergetRestApis:Assistant
No python3. Let me use the edit tool.
Assistant
No python available. Let me use the edit tool to add the method.
Assistant
Now add the equivalent to ApiGatewayV2Service. Let me find the getApis method:
Assistant
Now let me modify the
dispatchmethod in ApiGatewayExecuteController to resolve the correct region. Let me view the dispatch method's first lines:Assistant
Now I'll modify the
dispatchmethod. First, let me check the imports in the ExecuteController forOptional:Assistant
Now let me edit the dispatch method:
Assistant
Let me check the ApiGatewayAwsExecuteController to see if it's another data plane entry point that needs the same fix:
Assistant
Good, the
/_aws/execute-api/controller also delegates to dispatch, so the fix covers it. Let me also check the custom domain filter, since it might invoke the execute controller too:Assistant
Now let me compile the project to verify the changes build correctly:
Assistant
Compilation succeeded. Now let me write a reproduction test. First, let me understand the test config (RestAssured base URI/port) and how region is set via auth header in tests:
Assistant
Let me look at how tests set the region via the Authorization header:
Assistant
Now I understand how to set the region. Let me check the test storage config to understand if tests share persistent state:
Assistant
Storage is account-aware. Let me check the AccountAwareStorageBackend to understand the actual key format, since my
findRegionForRestApirelies on the key suffix:Assistant
The
keys()method strips the account prefix, soapiStore.keys()returns logical keys likeregion::apiId. MyfindRegionForRestApiworks correctly. Let me verify thecreatemethod wraps in AccountAware:Assistant
Let me check how the account ID is derived from the credential, to make sure my test will use the same account for create and invoke:
Assistant
Now I understand the account resolution. When AKID is not 12 digits, it defaults to
000000000000, same as no-auth. Let me create a temporary reproduction test:Assistant
The test ran through to cleanup. Let me see the explicit test result summary:
Assistant
All 6 tests pass. Now let me verify that the test actually fails WITHOUT my fix, to confirm the fix resolves the issue. Let me stash my source changes (but keep the temp test) and re-run:
Assistant
Confirmed: without the fix, the test fails with "Invalid API id specified". Now let me restore my fix:
Assistant
Now let me run the existing related tests to make sure nothing is broken. Let me run the apigateway tests:
Assistant
The
!triggers history expansion. Let me run specific test classes by name instead:Assistant
The
!is in my grep patternFAILURE!. Let me disable history expansion:Assistant
There are 11 failures in two authorizer-related tests. Let me check whether these failures are pre-existing (i.e., present without my change) by stashing and running just those two:
Assistant
These 11 failures are pre-existing (present without my change), so my fix doesn't introduce them. Let me restore my fix:
Assistant
The 11 failures are pre-existing. Let me also verify the apigatewayv2 tests still pass (since dispatch now affects v2 dispatch too):
Assistant
All v2 tests pass. Let me also verify the v2 cross-region fallback works with a quick test. Let me look at the v2 integration test for the flow:
Assistant
Let me find the execute-api invocation part of the v2 test (HTTP_PROXY integration with example.com). Let me look for how the test invokes the HTTP_PROXY and what it asserts. Actually, since the integration is HTTP_PROXY to https://example.com, invocation would make an outbound call. That's harder to test. Let me instead use a MOCK-like or a lambda proxy with a registered lambda.
Actually, let me check how the existing v2 test invokes - search for "execute-api" in the v2 test.
Assistant
The v2 test doesn't invoke via execute-api (uses HTTP_PROXY to example.com). Let me check how existing tests create Lambda functions for AWS_PROXY integration tests, so I can write a v2 cross-region test:
Assistant
The Lambda-based authorizer tests fail pre-existing (likely Docker unavailable in this env), so I can't reliably test v2 with Lambda. The v2 fallback mirrors v1 exactly and all existing v2 tests pass. Let me re-read my full dispatch edit to verify correctness:
Assistant
The edit is correct. Now let me remove the temporary test file and verify the final diff:
Assistant
Let me do a final compile to ensure everything is clean after removing the temp test:
Assistant
Compilation clean. Let me run the most directly related existing test one more time to confirm it passes with my changes:
Assistant
All tests pass. Let me review the final complete diff:
Assistant
The diff is clean and complete. Let me confirm there are no leftover temp test files:
Assistant
The solution is complete and the temp test is removed. Let me submit.
Summary of the fix
Root cause: The data-plane invocation path (
/restapis/{apiId}/{stageName}/_user_request_/{path}and/execute-api/{apiId}/{stageName}/{path}) resolves the region from the AWS header. When invoked without one (e.g. plain against a deployed API with ), the region falls back to the configured default (). But the API was created under the AWS CLI's region (), so the per-region lookup failed with . The management plane worked because those requests carried the header with the matching region.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.