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 understanding the repository structure and the issue. The issue is about API Gateway REST API path-based invocation returning 404 with "Invalid API id specified" when using the path format
/restapis/{id}/{stage}/_user_request_/{path}.Let me explore the repository first.
Assistant
This is a Java/Maven project. Let me search for the relevant API Gateway code that handles the data plane invocation path.
Assistant
Let me run commands one at a time
Assistant
Good, found the error sources. Let me examine both files, focusing on the REST API (v1) since the issue is about
/restapis/.Assistant
Let me look at the context around that line.
Assistant
Now let me find how the HTTP path
/restapis/{id}/{stage}/_user_request_/is routed. Let me search for the request handlerAssistant
Let me try without the -v grep for .git
Assistant
I found the key files. Let me look at the
ApiGatewayUserRequestController.javawhich handles the data plane requestsAssistant
Now let me look at the
ApiGatewayExecuteControllerto see how dispatch worksAssistant
Let me check the ApiGatewayController to see if there are path conflicts.
Assistant
Let me look at the specific methods around the
/restapis/{apiId}path in ApiGatewayAssistant
Let me check the class-level annotations for
Assistant
Let me look at the
apiKeymethod and how the region is resolvedAssistant
Let me find the
apiKeymethod definition and theRegionResolverclass.Assistant
Let me look at the
apiKeymethod at line 1258.Assistant
Let me check the RegionResolver's resolveRegion method.
Assistant
Let me look at how
apiGatewayV2Service.getApiworks to see if it might return a result for a v1Assistant
Let me look at the
getApimethod for v2.Assistant
Let me look at the JAX-RS application configuration to understand how the controllers are
Assistant
Let me look at the ApiGatewayUserRequestIntegrationTest
Assistant
Let me check how the JAX-RS application is configured
Assistant
Let me look at the application.yml files.
Assistant
Now I understand the issue. Let me verify by looking at how the API store works and whether we can scan all regions.
Assistant
Let me look at the StorageBackend interface to understand available methods
Assistant
Let me look at the full
dispatchmethod in `ApiGatewayExecuteControllerAssistant
Let me check the v2 service's key format
Assistant
Let me find the v2 apiKey method
Assistant
Now I understand the issue. When a data plane request comes in without an Authorization header (e.g., via curl), the region defaults to
us-east-1, but the API may have been created in a different region (e.g.,eu-west-2). The API is stored with keyeu-west-2::apiId, but the lookup usesus-east-1::apiId, causing the "Invalid API id specified" error.Let me first run the existing test to confirm the current state.
Assistant
The HOME variable is not set. Let me set it.
Assistant
The test passes because both creation and invocation use the same default region (
us-east-1). The issue occurs when the API is created in a different region (e.g.,eu-west-2) via AWS CLI with Authorization headers, but invoked via curl without Authorization headers, causing a region mismatch.Let me look at the full dispatch method to understand how to fix it
Assistant
Now I'll implement the fix. I need to:
- Add a method to
ApiGatewayServiceto find a REST API by ID across all regions - Add a similar method to
ApiGatewayV2Service - Modify the
dispatchmethod inApiGatewayExecuteControllerto fall back to region-agnostic lookup
Let me start by looking at the
ApiGatewayServiceto find a good place to add the method- Add a method to
Assistant
Let me add a method to find API by ID across all regions in
ApiGatewayService. First, let me open the file.Assistant
Let me use the open command properly
Assistant
Let me add the cross-region lookup method to
ApiGatewayService.java. I'll add it aftergetRestApis:Assistant
The file needs to be open first. Let me use the open command properly.
Assistant
Now let me add the
getRestApiByIdmethod aftergetRestApisAssistant
Now let me add a similar method to
ApiGatewayV2Service. Let me open that file first.Assistant
Now let me add the
getApiByIdmethod toApiGatewayV2ServiceAssistant
Now let me modify the
dispatchmethod inApiGatewayExecuteControllerto use the cross-region fallback. Let me open itAssistant
Now I need to add a method to get the region for a given API ID (to extract it from the key). Let me add this to both services. Let me first add to
ApiGatewayService:Assistant
I accidentally edited the wrong file! Let me revert that change.
Assistant
Now let me add the
getRestApiRegionmethod toApiGatewayService.javaproperly. Let me first verify the current state of that fileAssistant
Good, the
getRestApiByIdmethod is there. Let me addgetRestApiRegionafter itAssistant
Now let me add the
getApiRegionmethod toApiGatewayV2Service. Let me open itAssistant
Let me add
getApiRegionaftergetApiByIdAssistant
Now let me modify the
dispatchmethod inApiGatewayExecuteController.java. Let me open itAssistant
Now let me replace the
dispatchmethod with the cross-region fallbackAssistant
Good, the changes are in place. Let me now run the existing test to verify nothing is broken.
Assistant
The test passes. Let me also run a broader set of API gateway tests to make sure nothing is broken.
Assistant
Let me check if the build succeeded
Assistant
All 103 tests pass. Let me also run the authorizer and OpenAPI tests to make sure they still pass.
Assistant
Let me check if these test failures are pre-existing (not caused by my changes) by checking the error messages more closely
Assistant
These test failures are pre-existing (not caused by my changes). Let me restore my changes.
Assistant
Let me review the full diff of my changes
Assistant
Let me simplify the dispatch method to use only
getApiRegion/getRestApiRegionfor both existence check and region extractionAssistant
Let me simplify the dispatch method to use only
getApiRegion/getRestApiRegionfor both existence check and region extractionAssistant
Good. Let me run the tests again to confirm everything still passes with the simplified code.
Assistant
Let me also run OpenAPI import and stage method settings tests
Assistant
All tests pass. Let me verify the final diff
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.