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 start by exploring the repository structure to understand the codebase.
Assistant
Now let me look at the source structure to understand the API Gateway service.
Assistant
Let me look at the key API Gateway files - the user request controller and service.
Assistant
Let me look at the
getRestApimethod in the service to understand the context of "Invalid API id specified".Assistant
Let me look at the
dispatchmethod inApiGatewayExecuteController.java.Assistant
Now let me check the
regionResolver.resolveRegionmethod.Assistant
Let me look at the
createRestApimethod inApiGatewayService.javaand the controller.Assistant
Let me check existing tests to understand the expected behavior.
Assistant
Let me check what the current behavior is by running the existing test.
Assistant
Let me look at the AWS integration test which uses Lambda.
Assistant
Now let me check the AWS integration test which uses Lambda proxy.
Assistant
Let me look at how the storage backend works.
Assistant
Let me look at how to run the emulator.
Assistant
Let me try to reproduce the issue. First, let me start the emulator.
Assistant
Let me try to start the Quarkus app in dev mode. This might take a while.
Assistant
Now let me start the Quarkus app in dev mode in the background.
Assistant
The dev server is starting up. Let me wait for it to complete.
Assistant
Let me test by simulating the AWS CLI behavior using curl with a SigV4-shaped Authorization header.
Assistant
Good, the server is up. Now let me test by creating an API with a region different from the default. I'll use a SigV4-style Authorization header.
Assistant
This confirms my analysis. Now let me reproduce the full scenario.
Assistant
I've confirmed the issue. The problem is clear:
- When the API is created with region
eu-west-2, it's stored with keyeu-west-2::apiId - When the data plane invocation comes without an Authorization header, the region falls back to the default
us-east-1 - Lookup fails because the key
us-east-1::apiIddoesn't exist
Now let me plan the fix. The core issue is that API Gateway API IDs are globally unique. When invoking a data plane URL, the region from the Auth header might not match where the API was created.
Let me look at the full
dispatchmethod flow to understand all places where theregionvariable is used.- When the API is created with region
Assistant
Let me look at the dispatchV2 method for comparison.
Assistant
Let me look at the API Gateway v2 service to see if there's a similar pattern.
Assistant
Let me look at how the storage is configured.
Assistant
Let me look at the RestApi model.
Assistant
Let me look at the storage implementation to understand
scan.Assistant
Now I have a clear understanding. Let me implement the fix.
The cleanest approach is:
- Add a method
findRestApiById(String apiId)toApiGatewayServicethat searches across all regions - Modify the
dispatchmethod inApiGatewayExecuteControllerto use this fallback when the API isn't found in the resolved region
Let me first add a small helper to
ApiGatewayService:- Add a method
Assistant
Now let me add the helper method to find the API across regions. Let me first look at the structure of the imports and add a new method:
Assistant
Let me check where
getRestApiis called.Assistant
Let me stop the dev server first since I'll be making code changes.
Assistant
Let me add the helper method to
ApiGatewayService.java. I'll add it right aftergetRestApi.Assistant
Let me try a different approach using the
replacetool:Assistant
Let me use a different approach with a Python script to make the edit safely:
Assistant
Now let me modify the
dispatchmethod inApiGatewayExecuteController.javato use this fallback:Assistant
Now let me check if the dev server picked up the changes and recompiled:
Assistant
Let me check if the dev server has hot reload and trigger a recompile.
Assistant
The dev server isn't picking up the changes. Let me try to make a request to it and see if it works. First, let me check if it's still running.
Assistant
Let me wait and check the logs:
Assistant
The dev server has reloaded. Let me re-test:
Assistant
The API is found now. Let me also create a stage explicitly:
Assistant
The fix works. Now let me also check if the same issue exists for API Gateway V2 (HTTP API):
Assistant
The v2 path is at line 1142+. Let me look at it:
Assistant
Let me also fix v2. First, let me look at the v2 service:
Assistant
Let me also fix v2 for consistency. First, let me look at the
apiKeymethod in v2 service:Assistant
Let me verify the fix works for both paths by also testing
/execute-api/:Assistant
Now let me verify the negative case - when the API doesn't exist at all:
Assistant
Let me also verify the case where the API is created in the default region:
Assistant
Let me check if v2 has any execute path:
Assistant
Let me check the v2 execute path:
Assistant
Let me run the existing API Gateway tests to make sure I didn't break anything:
Assistant
Let me stop the dev server and run the existing tests:
Assistant
Tests pass. Let me also run a broader set of API Gateway tests:
Assistant
Let me check if these test failures are related to my fix or are pre-existing:
Assistant
The failures are pre-existing and not related to my changes. Let me restore my changes:
Assistant
Let me look at the diff to confirm the changes:
Assistant
Let me check the v2 path setup:
Assistant
Let me run the broader set of tests excluding the pre-existing failures:
Assistant
Let me check the
shortIdmethod to ensure the API ID format:Assistant
Let me check the InMemoryStorage thread safety:
Assistant
Let me also verify by running the tests in dev mode again to ensure everything still works:
Assistant
Let me create a temporary end-to-end script to verify the fix follows the exact scenario from the issue:
Assistant
Let me start the dev server again to do an end-to-end test:
Assistant
Let me also verify the error case is still handled correctly:
Assistant
Let me check the getStage method:
Assistant
Let me retest with a fresh API:
Assistant
Let me also verify by running the unit tests for the service:
Assistant
Let me clean up and do a final verification:
Assistant
Let me do a final review of the changes:
Assistant
Let me also clean up the dev log:
Assistant
Let me do a final check on the diff:
Assistant
The fix is complete and clean. Let me also verify the complete flow once more by running a final test:
Assistant
All tests pass. Let me do a final summary and review:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.