mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(apigatewayv2): provision integration, route and stage on quick create (#2877)
* fix(apigatewayv2): provision integration, route and stage on quick create CreateApi's `target` parameter (quick create) was accepted but silently ignored: no AWS_PROXY integration, no "$default" route, and no "$default" stage were ever created. Without a stage, ApiGatewayExecuteApiHostFilter.stageExists() throws "Stage not found", the filter returns without rewriting the request, and it falls through to whichever other virtual-hosted-style filter claims the host next (S3's, in the common case) instead of reaching the API. Provision the AWS_PROXY integration, "$default" route, and auto-deploy "$default" stage that real API Gateway creates for quick create, using the existing createIntegration/createRoute/createStage helpers. Fixes #1902 * fix(apigatewayv2): use HTTP_PROXY for HTTP URL quick-create targets Quick create hardcoded AWS_PROXY regardless of target shape, so an HTTP URL target got routed through Lambda ARN parsing and failed invocation instead of reaching the configured endpoint (spotted by review). Detect the target kind (arn: prefix vs HTTP URL) and pick AWS_PROXY/POST or HTTP_PROXY/ANY accordingly, matching real API Gateway's quick-create behavior. Also drop the em-dashes from the new comment and Javadoc per AGENTS.md's style rule, and split the single test into one covering each target kind. --------- Co-authored-by: Karan-Tekuncorked <karan@tekuncorked.com>
This commit is contained in:
1 parent
2bf9b57bd9
commit
2a637d3e05
2 files changed
+146
No files matched your search
+25
@@ -124,6 +124,31 @@ public class ApiGatewayV2Service {
|
||||
|
||||
apiStore.put(apiKey(region, api.getApiId()), api);
|
||||
LOG.infov("Created {0} API: {1} ({2}) in {3}", protocolType, api.getName(), api.getApiId(), region);
|
||||
|
||||
// Quick create: when the caller supplies Target (a Lambda ARN or HTTP URL), AWS
|
||||
// auto-provisions an integration, a "$default" catch-all route pointing at it, and an
|
||||
// auto-deploy "$default" stage. Without this the API has no route and no stage, so
|
||||
// ApiGatewayExecuteApiHostFilter's stage lookup fails and every invocation falls
|
||||
// through to whichever other virtual-hosted-style filter claims the request next.
|
||||
Object targetValue = request.get("target");
|
||||
String target = targetValue != null ? String.valueOf(targetValue) : null;
|
||||
if ("HTTP".equals(protocolType) && target != null && !target.isBlank()) {
|
||||
boolean isLambdaTarget = target.startsWith("arn:");
|
||||
Integration integration = createIntegration(region, apiId, Map.of(
|
||||
"integrationType", isLambdaTarget ? "AWS_PROXY" : "HTTP_PROXY",
|
||||
"integrationUri", target,
|
||||
"integrationMethod", isLambdaTarget ? "POST" : "ANY",
|
||||
"payloadFormatVersion", "2.0"));
|
||||
createRoute(region, apiId, Map.of(
|
||||
"routeKey", "$default",
|
||||
"target", "integrations/" + integration.getIntegrationId()));
|
||||
createStage(region, apiId, Map.of(
|
||||
"stageName", "$default",
|
||||
"autoDeploy", "true"));
|
||||
LOG.infov("Quick create: provisioned {0} integration, $default route and stage for API {1} -> {2}",
|
||||
integration.getIntegrationType(), apiId, target);
|
||||
}
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user