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 what we're working with.
Assistant
.Let me look at the issue more carefully. The bug is about API Gateway REST path-based invocation returning 404. This is likely a Java-based application since it uses Maven. Let me search for the relevant code.
Assistant
Now let me look at the
ApiGatewayUserRequestControllerto understand the restapis/{id}/{stage}/user_request/ endpoint.Assistant
Let me look at the full dispatch method to understand the issue:
Assistant
Let me search for "Invalid API id specified" message:
Assistant
Now let me find the apiKey function to understand how API keys are stored.
Assistant
Now let me look at how the region is resolved:
Assistant
Now let me look at how an API is created and the management endpoint to understand the region that's used.
Assistant
Now let me look at the controller for creating rest API to understand how the region is passed:
Assistant
Let me check the default region config:
Assistant
Now I need to understand the issue. Let me look at the storage layer:
Assistant
Let me check the V2 version's getApi:
Assistant
Let me search for existing tests for the user request controller:
Assistant
Let me look at the test resources to understand the default region for tests:
Assistant
Let me look at the integration test for the execute controller:
Assistant
Now let me look at the dispatch method to see how the region is used:
Assistant
Let me first try to build and verify the setup:
Assistant
Let me look at the
getResourcesmethod:Assistant
Let me first try to compile and run a test to make sure the build works:
Assistant
Let me focus on the bug. I understand the issue. Let me look at the storage backend implementations to see how the scan works:Let me check the storage backend implementation:
Assistant
Let me check the documentation:
Assistant
Now I have a clear picture. Let me check if there's a way to reproduce the issue with tests. Let me look at how the existing test invokes curl:
Assistant
Let me run the existing user request test to verify it works:
Assistant
The existing test passes because both the management plane and the data plane use the default region (us-east-1). The bug only manifests when the management plane is invoked in a different region than the data plane. Let me write a temporary script to reproduce the bug:
Assistant
Let me look at how the credentials are extracted:
Assistant
Now I understand the issue. Let me look at the existing tests to understand how to test this scenario:
Assistant
Now let me write a test script to reproduce the bug:
Assistant
The bug is confirmed. Both data plane endpoints fail with 404. Now let me implement the fix.
The fix should:
- Add a global API lookup method to
ApiGatewayServiceandApiGatewayV2Service - In the dispatch method, fall back to the global lookup when the region-specific lookup fails
- When the API is found via the global lookup, use the actual region of the API for subsequent operations
Let me look at the existing storage methods to understand:
- Add a global API lookup method to
Assistant
Now let me add a method to look up the API across all regions. First let me look at the imports and structure:
Assistant
Let me check the v2 dispatch:
Assistant
Let me check the findMatchingRoute method:
Assistant
Now let me implement the fix. First, I'll add a method to find the API region by ID in
ApiGatewayService:Assistant
Now let me add the
findApiRegionmethod:Assistant
I need to fix a formatting issue - the blank line between methods is missing. Let me also add the import for
Optional:Assistant
I made a mess. Let me revert and try again:
Assistant
Let me first add the
Optionalimport:Assistant
Now let me add the
findApiRegionmethod aftergetRestApi:Assistant
I need to add a blank line between the createRestApi close and getRestApi, and fix the structure of getRestApis:
Assistant
Let me reset and use a different approach:
Assistant
Let me add the import using sed first:
Assistant
Now let me carefully view the area to make the edit:
Assistant
Good. Now let me use sed to insert the method between getRestApi and getRestApis:
Assistant
The shell escape didn't work. Let me revert and use a direct approach:
Assistant
Let me use a different approach - read the entire file, modify it, and write it back:
Assistant
.Let me use perl to make the changes.
Assistant
Good. Now let me add the
findApiRegionmethod using a perl multi-line replacement:Assistant
Now let me use perl with -0 to insert the method:
Assistant
Let me use a perl script file instead:
Assistant
The pattern needs to match with
return apiStore.scan(k -> k.startsWith(prefix));\n }. Let me look more carefully:Assistant
The file content looks fine. The issue with the perl script is that I had an incorrect pattern. Let me debug:
Assistant
Now let me write a more reliable perl script:
Assistant
Let me fix the typo:
Assistant
Let me restructure the script:
Assistant
I need to add blank lines for proper formatting:
Assistant
The method has been added correctly. Now let me verify the file is still valid Java by compiling:
Assistant
Compiles successfully. Now let me add the same method to
ApiGatewayV2Service:Assistant
Both compile. Now let me update the dispatch method in
ApiGatewayExecuteControllerto use this fallback:Assistant
Let me look at how
findMatchingRouteworks for v2:Assistant
Now let me update the dispatch method to use the new fallback. Let me first look at the current implementation once more:
Assistant
Let me compile to make sure everything is OK:
Assistant
Now let me run the reproduce test:
Assistant
All 6 tests pass. The bug is fixed. Now let me also run the existing API Gateway tests to make sure I didn't break anything:
Assistant
All existing tests pass. Let me also run the v2 tests:
Assistant
All v2 tests pass. Let me also run the other api gateway tests:
Assistant
There are 11 test failures. Let me check if these are related to my change or pre-existing:
Assistant
The test failure is because Docker is not available (the Lambda function can't actually run in this environment). This is a pre-existing test issue, not related to my change. Let me verify by running these tests against the unchanged version:
Assistant
These failures are pre-existing (Docker is not available in the test environment). Let me restore my changes:
Assistant
Let me verify the existing tests still pass and the bug is fixed:
Assistant
All tests pass. Let me also run a broader test to ensure no other tests are broken:
Assistant
The full test run takes too long because of Docker-dependent tests. Let me focus on running tests that are most relevant to my change. Let me run the most important ones:
Assistant
All 381 relevant tests pass. Let me also look more carefully at the v2 dispatch to see if there's anything I should also fix there:
Assistant
Now let me also verify that the
RegionResolvercorrectly handles the case where there's no Authorization header by re-reading the issue. Looking at the issue:awsCLI uses eu-west-2 (region in Authorization header)curlhas no Authorization header → region resolves to default us-east-1
The default region is
us-east-1in the test config, so my reproduce script correctly shows the bug.Let me also consider edge cases:
- What if the API doesn't exist at all? Returns 404 "Invalid API id specified" ✓
- What if the user provides an Authorization header with the correct region? Uses the region-specific lookup ✓
- What if there are multiple regions? Uses the first one found ✓
- What about WebSocket connections? The dispatch method is the same, so the fix applies ✓
Let me also verify that the v1 region is being used properly when invoking Lambda. Let me look at the v1 dispatch path:
Assistant
Let me write a more comprehensive test to verify both v1 and v2 work correctly:
Assistant
Let me check the logs:
Assistant
Let me check the v2 MOCK integration handling:
Assistant
The 500 is a pre-existing issue with MOCK integration in v2, not related to my fix. Let me delete the temporary test:
Assistant
Good, the test files are removed. Now let me look at the final state of my changes:
Assistant
Let me run the final verification with all the relevant tests:
Assistant
All 381 tests pass. Let me clean up any temporary files I created:
Assistant
Let me also remove the .bak file that was created during the test:
Assistant
Now let me verify the final state of my changes:
Assistant
Let me view the final dispatch method to make sure everything is consistent:
Assistant
Let me also verify the test once more to ensure my fix works:
Assistant
All 7 tests pass:
- API created in
eu-west-2 - Invoked via
/restapis/{id}/prod/_user_request_/hello(no Authorization) → 200 - Invoked via
/execute-api/{id}/prod/hello(no Authorization) → 200 - Nonexistent API → 404 with "Invalid API id specified"
Let me clean up the temporary test file:
- API created in
Assistant
Let me also run a final comprehensive test of all the api gateway tests to be sure:
Assistant
All 381 tests pass. The fix is complete.
Summary
Issue
The data plane invocation path (
/restapis/{id}/{stage}/_user_request_/{path}) returned 404 "Invalid API id specified" when the API was created in a different region than the one resolved from the incoming request.Assistant
The changes are ready to be submitted. Let me do a final review:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.