我尝试在AWS Lambda中部署一个具有多种功能的Spring Cloud Function。
为了访问超文本传输协议,我创建了一个HTTP API Gateway (not a REST API)。我想使用这里描述的函数路由:https://cloud.spring.io/spring-cloud-static/spring-cloud-function/3.0.1.RELEASE/reference/html/spring-cloud-function.html#_function_routing。
使用以下配置,RoutingFunction应根据function HTTP-Header删除对正确函数的调用
spring.cloud.function.routing-expression=headers.functionLambda处理程序类是:
org.springframework.cloud.function.adapter.aws.SpringBootApiGatewayRequestHandler配置的函数名(FUNCTION_NAME)为:functionRouter。
当我向API-Gateway发送请求时,FunctionRouter会得到一个FluxJust对象,而不是一个消息对象,因为RequestHandler似乎是一个发布者。因此,我得到了以下异常:
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?我目前的解决方法是在将请求委托给RoutingFunction之前拦截该请求,并尝试使用以下代码从HashMap重新构建有效负载:
@Autowired
RoutingFunction f;
@Bean
public Function<Message<LinkedHashMap>,?> router() {
return value -> {
String json = new JSONObject(value.getPayload()).toString();
Message<?> m = MessageBuilder.createMessage(json, value.getHeaders());
Object result = f.apply(m);
return result;
};
}有没有一种在AWS中结合使用HTTP API Gateway和Function Routing的正确方法
发布于 2020-07-05 22:21:15
在我的项目中,我已经这样设置了function.definition和function.routing-expression:
spring.cloud.function.definition=functionRouter
spring.cloud.function.routing-expression=headers['pathParameters']['proxy']这将使用Spring Cloud Function提供的org.springframework.cloud.function.context.config.RoutingFunction,表达式将从路径中获取函数名。
如果你仍然想使用头文件,你可以这样做:spring.cloud.function.routing-expression=headers['headers']['function']。HTTP头被添加到headers属性的消息头中。因此,我们首先获取消息头,然后是HTTP头,然后是头键。
https://stackoverflow.com/questions/59778471
复制相似问题