title: Spring Cloud Function with Function Routing in AWS Lambda using API Gateway
body: <p>I have tried to deploy a <code>Spring Cloud Function</code> with multiple functions in AWS Lambda.</p>
  
  <p>For HTTP access I have created an <code>HTTP API Gateway (not a REST API)</code>. I wanted to use function routing as described here: <a href="https://cloud.spring.io/spring-cloud-static/spring-cloud-function/3.0.1.RELEASE/reference/html/spring-cloud-function.html#_function_routing" rel="nofollow noreferrer">https://cloud.spring.io/spring-cloud-static/spring-cloud-function/3.0.1.RELEASE/reference/html/spring-cloud-function.html#_function_routing</a>.</p>
  
  <p>With the following configuration, the <code>RoutingFunction</code> shoud deleagte the call to the correct function based on the <code>function HTTP-Header</code>:</p>
  
  <pre><code>spring.cloud.function.routing-expression=headers.function
  </code></pre>
  
  <p>The Lambda Handler class is:</p>
  
  <pre><code>org.springframework.cloud.function.adapter.aws.SpringBootApiGatewayRequestHandler
  </code></pre>
  
  <p>and the configured function name (<code>FUNCTION_NAME</code>) is: <code>functionRouter</code>.</p>
  
  <p>When I send a Request to the API-Gateway, the FunctionRouter gets a FluxJust object instead of a Message object, because the RequestHandler seems to be a Publisher.
  So I get the following exception:</p>
  
  <pre><code>EL1008E: Property or field 'headers' cannot be found on object of type
  'reactor.core.publisher.FluxJust' - maybe not public or not valid?:
  org.springframework.expression.spel.SpelEvaluationException
  
  org.springframework.expression.spel.SpelEvaluationException:
  EL1008E: Property or field 'headers' cannot be found on object of type
  'reactor.core.publisher.FluxJust' - maybe not public or not valid?
  </code></pre>
  
  <p>My current workaround is to intercept the request before the request is delegated to the <code>RoutingFunction</code> and try to reconstruct the payload from the <code>HashMap</code> with the following code:</p>
  
  <pre><code>@Autowired
  RoutingFunction f;
  
  @Bean
  public Function&lt;Message&lt;LinkedHashMap&gt;,?&gt; router() {
      return value -&gt; {
          String json = new JSONObject(value.getPayload()).toString();
          Message&lt;?&gt; m = MessageBuilder.createMessage(json, value.getHeaders());
          Object result = f.apply(m);
          return result;
      };
  }
  </code></pre>
  
  <p>Is there a way proper way to use the HTTP API Gateway in combination with <code>Function Routing</code> in <code>AWS</code>?</p>