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 explore more about the API Gateway related code.
Assistant
Now let me check the API Gateway AWS service router to see how requests are routed.
Assistant
Let me search for the "Invalid API id" message to understand where this 404 comes from.
Assistant
Now let me find the dispatch method in the execute controller to understand how the API is looked up.
Assistant
Now let me look at the storage key strategy used for apigateway.
Assistant
Now let me look at the dispatch and the region resolution to understand the issue.
Assistant
Now let me look at the existing tests for this execute controller to understand the expected behavior.
Assistant
Let me first understand if there's an issue with how the test setup is happening vs the actual user reported issue. Let me try to build the project to see if everything compiles.
Assistant
Let me first run the existing test for the user request path to see if it works.
Assistant
Let me check the region resolution and how the API is created.
Assistant
Let me understand the issue. When the user creates the API in
eu-west-2(with AWS SigV4 auth) and then invokes it viacurl(without auth), the lookup uses the default regionus-east-1instead ofeu-west-2. Let me verify this hypothesis.Assistant
Let me also look at the v2 service which has a similar structure.
Assistant
Let me look at the AccountAwareStorageBackend more carefully to understand the key structure.
Assistant
Let me see how many call sites of
getRestApiexist.Assistant
Let me look at the storage keys more carefully.
Assistant
Now let me create a test to reproduce the issue first.
Assistant
I've successfully reproduced the issue. Now let me fix the test and implement the fix.
Assistant
Now I've confirmed the issue. Let me implement the fix. The approach is to add a method to find the actual region for an API by scanning all regions, then use that region for all subsequent operations.
Assistant
Let me add the
findApiRegionmethod toApiGatewayService.Assistant
Now let me add the
findApiRegionmethod aftergetRestApi:Assistant
Now let me add a similar method to
ApiGatewayV2Service:Assistant
I see the edit corrupted the file. Let me fix it.
Assistant
I see there's still a duplicate
return apiStore.scan(k -> k.startsWith(prefix));line. Let me fix that.Assistant
Let me look at the broader area of the file to see what's happening.
Assistant
The file is corrupted. Let me restore it from git.
Assistant
Good, the file is restored. Now let me add the
findApiRegionmethod more carefully.Assistant
The edit duplicated the imports. Let me restore and try a different approach.
Assistant
Now let me add the
findApiRegionmethod aftergetApi. Let me find the exact location first.Assistant
Now let me use
replaceto insert the new method.Assistant
Let me use a different approach with sed to insert the method.
Assistant
Now let me verify the file compiles correctly.
Assistant
Now let me update the
dispatchmethod inApiGatewayExecuteControllerto usefindApiRegionfor region fallback.Assistant
Let me update the
dispatchmethod to use region fallback.Assistant
Let me write the perl script to a file instead.
Assistant
Now I need to add the
Optionalimport to the controller. Let me check the current imports.Assistant
I need to add the
Optionalimport.Assistant
Now let me compile to check.
Assistant
Compilation succeeded. Now let me run the reproduction test to see if the fix works.
Assistant
The reproduction test now passes. Let me also run the existing user request test to make sure I didn't break anything.
Assistant
Now let me run all the existing API Gateway tests to make sure I didn't break anything.
Assistant
Let me investigate the test failures in
ApiGatewayRequestAuthorizerIntegrationTest.Assistant
Let me check if the test was passing before my change.
Assistant
The test was failing even before my change. Let me restore my changes and check the full test class.
Assistant
The test was already failing before my change (it's a pre-existing issue with Docker/Lambda in the test environment). Let me restore my changes.
Assistant
Let me run other API Gateway tests that don't depend on Docker/Lambda to verify my changes.
Assistant
All 75 tests pass. Now let me also run the v2 tests to make sure those work too.
Assistant
All 218 v2 tests pass. Now let me think about edge cases and potential issues with my fix.
-
Performance: The
findApiRegionmethod scans all keys in the store. This is called on every request. For a large number of APIs, this could be slow. But since this is an emulator, the number of APIs is typically small. -
Multiple APIs with the same ID in different regions: The method returns the first one found. This is an edge case that's unlikely in practice.
-
The fallback should only happen when the API is not found in the resolved region: Currently, I'm always calling
findApiRegion, which is inefficient. Let me optimize this by only calling it when the initial lookup fails.
Let me optimize the fix:
-
Assistant
Let me look at the current code and improve it to handle the case where the API is v2 in a different region.
Assistant
Let me update the dispatch method to handle the edge case where the API is v2 in a different region.
Assistant
Now let me compile and run the tests.
Assistant
Now let me run the other API Gateway tests to make sure nothing is broken.
Assistant
All tests pass. Now let me also run the full test suite to check for any regressions.
Assistant
Let me check if these failures are pre-existing.
Assistant
The failures are pre-existing. Let me run the full test suite to get a baseline.
Assistant
Let me verify the baseline by running the same tests without my change.
Assistant
Let me also check the custom domain filter to see if it has the same issue.
Assistant
Let me also check the AwsExecuteController to see if it has the same issue.
Assistant
Let me also check the
dispatchV2method.Assistant
Let me remove the test file I created for reproducing the issue, as the instructions say not to add new tests.
Assistant
Good, the test file is removed. Now let me also think about one more edge case. Let me check if there are any issues with the
dispatchV2method when the API is not found.Assistant
Let me run the custom domain test to make sure it still works.
Assistant
Now let me look at the final state of the changes and make a summary.
Assistant
Let me run the tests one more time to make sure everything passes.
Assistant
All 293 tests pass. Now let me also think about whether I should also handle the case where the API is found but the stage is not. Let me also think about whether there are any other edge cases.
Let me also consider the case where the same API ID exists in multiple regions. In that case,
findApiRegionwould return the first one found. This is acceptable behavior since API IDs are supposed to be globally unique.Let me also consider the case where the storage is persistent (not in-memory). The
findApiRegionmethod usesapiStore.keys(), which should work for all storage backends.Let me also verify the fix works for the WebSocket API case.
Assistant
All WebSocket tests pass. Now let me also check if there are any other tests I should run.
Assistant
Let me do a final verification by running the existing user request test.
Assistant
All tests pass. Now let me also look at the final state of the changes.
Assistant
The changes are minimal and focused:
-
ApiGatewayService.java: AddedfindApiRegion(String apiId)method that scans all stored API keys to find the region where an API is stored. -
ApiGatewayV2Service.java: Added the samefindApiRegion(String apiId)method for v2 APIs. -
ApiGatewayExecuteController.java: Updated thedispatchmethod to usefindApiRegionas a fallback when the API is not found in the resolved region. This handles the case where the request doesn't include an AWS SigV4 Authorization header (e.g., a plaincurlrequest), which causes theRegionResolverto return the default region instead of the region where the API was created.
Let me also verify the fix by looking at the final dispatch method:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.