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 start by understanding the repository structure and the issue. The issue is about API Gateway REST API path-based invocation returning 404. The path format
/restapis/{id}/{stage}/_user_request_/{path}should route requests through API Gateway to the Lambda function, but instead returns "Invalid API id specified".Let me first explore the repository structure to understand what we're dealing with.
Assistant
This looks like a Java project - Floci (a local cloud stack). Let me explore the source and find the relevant API Gateway code.
Assistant
Let me look for API Gateway related files.
Assistant
Let me look at the key files related to the
_user_request_path and routing.Assistant
Let me use the correct special command:
openwith proper syntax.Assistant
Let me look at the
ApiGatewayExecuteControllerand theAwsServiceRouter.Assistant
Let me look at the dispatch method.
Assistant
Let me look at the dispatch method at line 226.
Assistant
Now let me look at the AwsServiceRouter to understand how requests are routed to the execute controller. Let me also check how the path
/restapis/{apiId}/{stageName}/_user_request_/{proxy}gets routed to the correct controller.The issue is that the API Gateway management plane operations (like
create-rest-api,get-resources) use the path/restapis/{id}/...but these are separate from the data plane path/restapis/{id}/{stage}/_user_request_/{path}.Let me look at the AwsServiceRouter to see how it routes requests.
Assistant
This AwsServiceRouter is about AWS integration routing, not about request routing. Let me look at the main API Gateway controller.
Assistant
Let me look for how the ApiGatewayController might be conflicting with the user request controller. Let me check if there's a path conflict
Assistant
Let me search for the "Invalid API id specified" error message
Assistant
Let me look at the ApiGatewayService to understand how APIs are stored
Assistant
Let me look at the
getRestApi,createRestApi, andgetStagemethodsAssistant
Let me look at these methods in
Assistant
Let me look at the key methods used for storing:
Assistant
Now let me look at the
apiKeymethod to understand the key format:Assistant
Let me check how region resolution works, and also look at
RegionResolver.Assistant
Let me look at the integration test for the user request controller
Assistant
Let me see the rest of the test:
Assistant
Let me check how
createDeploymentworks in the controller:Assistant
Let me look at the createDeployment method in the controller and
Assistant
Let me go to the right file.
Assistant
Let me look at the
createDeploymentmethod in the service:Assistant
I think I found the issue! When creating the API via AWS CLI, the region is resolved from the Authorization header as
eu-west-2. But when invoking viacurl(which doesn't send an Authorization header), the region falls back to the default region (likelyus-east-1). The API was stored undereu-west-2::<apiId>, but looked up underus-east-1::<apiId>, resulting in "Invalid API id specified".Let me verify this theory by checking the default region
Assistant
Let me check the EmulatorConfig to see the default region:
Assistant
Let me first run the existing integration test to see if the
_user_request_path works in testsAssistant
HOME is not set. Let me try setting it.
Assistant
The test passes, confirming the
_user_request_path works correctly within the test framework. The issue must be about region mismatch: when creating via AWS CLI, the region comes from the Authorization header (e.g.,eu-west-2), but when invoking viacurl(no Authorization header), the region defaults tous-east-1.Let me verify by looking at the StorageBackend to understand how we could search across regions:
Assistant
Let me look at StorageBackend to understand the available methods.
Assistant
Let me look at the dispatch method more carefully to understand the full
Assistant
I need to open the file again.
Assistant
Let me also look at
ApiGatewayV2Service.getApito see the same patternAssistant
Now I have a clear understanding. Let me implement the fix. The issue is that the
dispatchmethod uses the region from headers to look up the API. When calling viacurl(no Authorization header), the region defaults tous-east-1but the API might be in a different region (likeeu-west-2).I'll:
- Add a
findRestApiRegion(String apiId)toApiGatewayServiceto find the API across all regions - Add a
findApiRegion(String apiId)toApiGatewayV2Servicesimilarly - Update
dispatchto fall back to cross-region search
First, let me add the cross-region lookup to `ApiGatewayService
- Add a
Assistant
Now I'll add the
findRestApiRegionmethod toApiGatewayService. Let me first check the importsAssistant
Now let me implement the changes. First, add the cross-region lookup to
ApiGatewayService:Assistant
I see an issue - the
"::"string was not properly inserted. Let me fix the method:Assistant
I need to fix the string literal. Let me use replace to fix it:
Assistant
Good. Now let me add the same kind of method to
ApiGatewayV2Service:Assistant
Let me look at the
getApimethod inApiGatewayV2Service:Assistant
Now let me add
findApiRegionto `ApiGatewayV2ServiceAssistant
Now let me modify the
dispatchmethod inApiGatewayExecuteControllerto fall back to cross-region lookup:Assistant
Now let me modify the
dispatchmethod to support cross-region lookup. I'll replace lines 226-252Assistant
The dispatch method now falls back to cross-region lookup. Let me verify the changes compile and the
Assistant
Good, the test passes. Let me also run a broader set of API Gateway tests to make sure nothing is broken
Assistant
All tests pass. Now, I also want to address the secondary issue: in AWS,
create-deployment --stage-name devshould also create a stage. Let me check if this is already handled or needs fixingAssistant
Let me also fix the
createDeploymentto auto-create a stage whenstageNameis provided (standardAssistant
The edit introduced duplicate code and misplaced the method. Let me revert and redo this properly. Let me first see the current state of the file around the affected area:
Assistant
Good, reverted. Let me re-apply changes carefully. First, add
findRestApiRegionAssistant
Good. Now let me update
createDeploymentto auto-create stage whenstageNameis provided. Let me look at the current method:Assistant
Now let me update
createDeploymentto auto-create stage whenstageNameis provided:Assistant
Good. Now let me run all the API Gateway tests to make sure everything still works
Assistant
Let me check if these failures are pre-existing by first reverting my changes and running the same tests
Assistant
The failures are pre-existing (9 failures without my changes). Let me restore my changes:
Assistant
Let me run the core API Gateway tests excluding the pre-existing failing one to verify my changes are good:
Assistant
Let me see which tests are failing:
Assistant
Let me check if these failures are also pre-existing:
Assistant
These failures are pre-existing. Let me restore my changes:
Assistant
Let me also check if the
ApiGatewayCustomDomainFilterneeds similar changes:Assistant
All pre-existing failures are confirmed. Let me now run the key tests once more to make sure everything passes with my
Assistant
All key tests pass. Let me review the final diff to make sure all changes are correct
Assistant
The diff looks clean. Let me run the full set of API Gateway tests one more time to confirm everything is good:
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 →