代码之家  ›  专栏  ›  技术社区  ›  Rahul

在aws lambda中使用APIGatewayProxyRequestEvent时如何获取日志记录的上下文

  •  0
  • Rahul  · 技术社区  · 2 年前

    我的项目是用spring cloud函数编写的,部署在aws lambda中。我有一个要求,我应该记录事件。

    搜索了一下让我用

    com.amazonaws.services.lambda.runtime.Context 通过这样做进行日志记录:

    context.getLogger().log("log event here");
    

    我有一个spring cloud函数,它接收APIGatewayProxyRequestEvent作为输入,接收APIGatewayProxyResponseEvent作为输出参数

    我再次搜索,找到了上下文,可以用 org.springframework.messaging.Message

    所以我写了这样的函数:

    public Function<Message<APIGatewayProxyRequestEvent>, APIGatewayProxyResponseEvent> saveEmployee(){
    return request -> {
                Context context = request.getHeaders().get("aws-context", Context.class);
    context.getLogger().log("employee save request---: " + request);
        //do something
    

    然而,上下文的计算结果为null,我得到了NullPointerException

    有人能指出可能出了什么问题吗?或者如何获取上下文?

    提前谢谢

    0 回复  |  直到 2 年前
    推荐文章