diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/CustomRuntimeEventLoop.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/CustomRuntimeEventLoop.java index 83d9f256d..01fd9cbde 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/CustomRuntimeEventLoop.java +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/CustomRuntimeEventLoop.java @@ -130,7 +130,7 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle { } if (response != null) { - FunctionInvocationWrapper function = locateFunction(environment, functionCatalog, response.getHeaders().getContentType()); + FunctionInvocationWrapper function = locateFunction(environment, functionCatalog, response.getHeaders()); Message eventMessage = AWSLambdaUtils.generateMessage(response.getBody().getBytes(StandardCharsets.UTF_8), fromHttp(response.getHeaders()), function.getInputType(), mapper); if (logger.isDebugEnabled()) { @@ -172,7 +172,8 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle { return null; } - private FunctionInvocationWrapper locateFunction(Environment environment, FunctionCatalog functionCatalog, MediaType contentType) { + private FunctionInvocationWrapper locateFunction(Environment environment, FunctionCatalog functionCatalog, HttpHeaders httpHeaders) { + MediaType contentType = httpHeaders.getContentType(); String handlerName = environment.getProperty("DEFAULT_HANDLER"); if (logger.isDebugEnabled()) { logger.debug("Value of DEFAULT_HANDLER env: " + handlerName); @@ -201,6 +202,15 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle { function = functionCatalog.lookup(handlerName, contentType.toString()); } + if (function == null) { + logger.info("Could not determine DEFAULT_HANDLER, _HANDLER or 'spring.cloud.function.definition'"); + handlerName = httpHeaders.get("spring.cloud.function.definition"); + if (logger.isDebugEnabled()) { + logger.debug("Value of 'spring.cloud.function.definition' header: " + handlerName); + } + function = functionCatalog.lookup(handlerName, contentType.toString()); + } + Assert.notNull(function, "Failed to locate function. Tried locating default function, " + "function by 'DEFAULT_HANDLER', '_HANDLER' env variable as well as'spring.cloud.function.definition'. " + "Functions available in catalog are: " + functionCatalog.getNames(null));