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
I'll start by exploring the repository structure to understand the codebase and locate relevant files for the API Gateway REST path-based invocation issue. Let's first get an overview.
- Assistant
Let me explore the repository structure more thoroughly to understand the project and find the API Gateway implementation.
- Assistant
This is a Java project (Maven-based). Let me look for the API Gateway related code.
- Assistant
Let me look at the key files related to the API Gateway routing, specifically the
ApiGatewayUserRequestController.javaandAwsServiceRouter.javafiles since these are likely responsible for handling the/restapis/{id}/{stage}/_user_request_/{path}route. - Assistant
Now let me look at the
ApiGatewayExecuteController.javato understand thedispatchmethod. - Assistant
Let me look at the AwsServiceRouter.java and ApiGatewayService.java to understand how the routing works.
- Assistant
Now let me look at the ApiGatewayService.java to understand how it handles API lookups:
- Assistant
Let me look at the main API Gateway controller (management plane):
- Assistant
Now let me look at the
ApiGatewayAwsExecuteController.javafile: - Assistant
Now I need to understand the routing conflict. The
ApiGatewayControllerhas@Path("/")and likely has a@GET @Path("/restapis/{apiId}")method that's matching the user request path before theApiGatewayUserRequestControllergets a chance. Let me look at the full ApiGatewayController to see all its paths: - Assistant
Let me see all paths in the ApiGatewayController:
- Assistant
Let me look for any request filter or routing logic that handles incoming requests:
- Assistant
Now let me understand the flow better. Let me look at the dispatch method in
ApiGatewayExecuteControllermore closely, particularly the region resolution: - Assistant
Let me look at the dispatch method:
- Assistant
Let me check if there are tests for this path-based invocation:
- Assistant
Let me look at the test file:
- Assistant
Now I understand the test setup. Let me look at the RegionResolver to understand how region resolution works:
- Assistant
Let me look for any request filters that might be intercepting the
/restapis/path: - Assistant
Let me check for any filters that might affect API Gateway routing:
- Assistant
Let me run the existing tests to see if they pass:
- Assistant
Let me check if there's a Maven wrapper available or we need to use a different build command.
- Assistant
The test passes! So the basic routing works fine. The issue must be more subtle. Let me look at the
RegionResolverand understand how the region is resolved when usingcurldirectly (without AWS SDK headers): - Assistant
Now I see the issue! The
RegionResolver.resolveRegion()extracts the region from theAuthorizationheader. When usingcurldirectly (no Authorization header), it returns thedefaultRegion. But the API was created with a different region (eu-west-2). Let me check the default region configuration: - Assistant
Wait, the test passes. Let me look more carefully at the issue. The issue says the user is using
eu-west-2region. Let me check if there's a region mismatch issue. TheRegionResolverresolves from Authorization headers, but when usingcurldirectly, there's no Authorization header. Let me look at the issue again and understand the flow better: - Assistant
Now I understand the issue! The
RegionResolverresolves the region from theAuthorizationheader. When usingcurldirectly (without AWS SDK headers), there's no Authorization header, so it defaults tous-east-1. But if the API was created in a different region (e.g.,eu-west-2), the lookup fails with "Invalid API id specified".The fix should be in the
dispatchmethod to try finding the API across all regions when the default region lookup fails. Let me check how to get all regions: - Assistant
Let me look at the StorageBackend interface to understand how to scan for APIs by ID regardless of region:
- Assistant
Let me understand the test. The test passes, which means the basic routing works. The issue must be specific to the user's scenario. Let me re-read the issue and look more carefully at the path routing:
- Assistant
The test passes, so the routing itself works. Let me re-read the issue more carefully. The key detail is the region:
eu-west-2. When usingcurldirectly, there's no Authorization header, so the region resolves tous-east-1(default). But the API was created witheu-west-2via the AWS CLI. Let me verify this hypothesis: - Assistant
Let me look at the key generation:
- Assistant
Let me see the key format:
- Assistant
Let me now understand the issue better. I believe the problem is a region mismatch. When a user creates an API using AWS CLI with
eu-west-2region, but then invokes viacurlwithout region headers, the default regionus-east-1is used and the API isn't found. Let me also look at how thegetStagemethod works: - Assistant
Now I understand the issue completely. The problem is region mismatch: when a user creates an API with the AWS CLI (which sends Authorization headers with region info like
eu-west-2), but then invokes viacurlwithout any Authorization headers, the default regionus-east-1is used and the API lookup fails.The fix should make the
dispatchmethod inApiGatewayExecuteControllerfind the API regardless of region when the initial lookup fails. In real AWS, the API ID is globally unique, so the/restapis/{apiId}path should work regardless of the region used.Let me add a method to
ApiGatewayServicethat looks up an API by ID across all regions: - Assistant
Now let me add a method to
ApiGatewayServicethat can find a REST API by ID regardless of region: - Assistant
Let me look at the
RegionResolvermore carefully: - Assistant
Now I understand the bug! The issue is region mismatch. When the user creates an API via AWS CLI with region
eu-west-2, the API is stored under keyeu-west-2::${apiId}. But when they invoke viacurl(which has no Authorization header), the region resolves tous-east-1(default), and the lookup forus-east-1::${apiId}fails with "Invalid API id specified".The fix should be: in the
dispatchmethod, when the API is not found in the resolved region, fall back to searching all regions. Let me implement this: - Assistant
Now I need to add a method to
ApiGatewayServicethat finds a REST API by ID regardless of region. Let me add it: - Assistant
Now I understand the issue. The API is stored with region-specific keys (
eu-west-2::apiId), but whencurlis used without auth headers, the region defaults tous-east-1. Let me add a fallback method toApiGatewayServiceto find an API by ID across all regions: - Assistant
I see the edit created duplicate lines. Let me fix that:
- Assistant
I see there's a duplicate line. Let me fix it:
- Assistant
Wait, let me reconsider. Instead of adding a separate method with
Object[], let me just modify thedispatchmethod directly. Let me first revert thefindRestApiAcrossRegionsmethod and instead modify thedispatchinApiGatewayExecuteController: - Assistant
Let me clean up the empty line and think about a better approach. Let me first clean up the file:
- Assistant
Good, the file looks clean now. Let me add the method back using a cleaner approach - a proper record:
- Assistant
Now I need to add a blank line before
deleteRestApi: - Assistant
Good, the
ApiGatewayServicenow has thefindRestApiAcrossRegionsmethod. Now I need to modify thedispatchmethod inApiGatewayExecuteControllerto use this fallback. Let me update the dispatch method: - Assistant
Now let me update the dispatch method to use the cross-region lookup as a fallback:
- Assistant
Now let me modify the dispatch method to use the cross-region lookup:
- Assistant
Good, the dispatch method is updated. Now let me run the test to make sure it still passes:
- Assistant
The existing test passes. Now let me run all the API Gateway related tests to make sure nothing is broken:
- Assistant
Let me check if these test failures are pre-existing by checking out the original code:
- Assistant
Good, those failures are pre-existing. Let me restore my changes and run just the API Gateway tests that matter:
- Assistant
Let me run the API Gateway tests excluding the pre-existing failures:
- Assistant
I need to escape the
!character. Let me use a different approach. - Assistant
All 40 tests pass. Now let me also run the AWS integration test and custom domain test:
- Assistant
All tests pass. Now let me verify the changes are correct by looking at both modified files:
- Assistant
Good. The diff looks clean. Let me also fix a missing blank line in the
ApiGatewayService.java: - Assistant
Let me fix the missing blank line:
- Assistant
Good, the file looks clean now. Let me run the full test suite one more time to confirm everything passes:
- Assistant
All 95 tests pass. Now let me also check the
dispatchV2path for the same issue. Let me look at the v2 dispatch to see if it also needs the cross-region fallback: - Assistant
Let me also look at the v2 dispatch to make sure it handles region correctly:
- Assistant
Let me also consider if the V2 API check needs the same fallback. Looking at the dispatch method, the V2 check also uses the resolved region:
- Assistant
Let me check if the V2 API also has the same region issue. Looking at the
dispatchV2method, theregionis passed to it from the dispatch method. If the V2 API was created in a different region, the initial V2 check would fail and fall through to v1 handling. However, since the issue is specifically about REST APIs (v1), and the V2 check silently catches the exception, my fix should still work correctly for the reported issue.Now let me also think about whether the
regionvariable can be reassigned in the catch block. In Java, local variables can be reassigned as long as they're not captured in a lambda or anonymous class. Let me verify: - Assistant
Wait, I just realized there's a problem with the
regionvariable. In Java, you can't reassign a local variable in a catch block if it was already used before the try. Actually, you CAN reassign it - the issue would be if it were captured in a lambda. But let me check if theregionvariable needs to be afinalor effectively final. Let me verify the code compiles and runs correctly: - Assistant
The code compiles and runs. Let me also check that the
regionvariable reassignment doesn't cause any issues with Java's effectively-final requirement. Sinceregionis only passed as a parameter (not captured in lambdas), this should be fine.Now let me also consider if the V2 API check needs the same fix. Let me look at the full dispatch flow:
- Assistant
I notice there's a potential issue: the
regionvariable is reassigned in the inner try-catch block, but Java might complain about it not being effectively final if it's used in a lambda or anonymous class downstream. Let me verify the code is correct. Actually, looking at the code,regionis only used as a direct parameter in method calls, not in lambdas, so this should be fine.Let me verify the final diff:
- Assistant
The diff looks clean. Let me run the full API Gateway test suite one more time to confirm everything is good:
- Assistant
Wait, I notice that the Execute test and CustomDomain test aren't showing up in the output. Let me check if they were actually run:
- Assistant
Let me check what the exact test class names are:
- Assistant
Let me also run those tests to make sure they pass.
- Assistant
All tests pass. Let me now verify the final state of the changes:
- Assistant
Now let me review the final changes one more time to make sure they're correct:
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 →