简体   繁体   English

如何在Java中访问AWS Lambda回调结果

[英]How to access AWS Lambda callback results in Java

I am calling an AWS Lambda function written in NodeJS which exports: 我正在调用用NodeJS编写的AWS Lambda函数,该函数将导出:

exports.handler = (event, context, callback) => {

The callback is passed the output of a SQL query: 回调传递给SQL查询的输出:

new mssql.Request(conn).query(passedStatement,(err, result) => {
    if (err) {
        callback(err);
    } else {
        console.log("done");
        callback(null, result);
    }
});

I am calling this function from Java code: 我从Java代码中调用此函数:

InvokeRequest request = new InvokeRequest()
        .withFunctionName(lambdaFunctionName)
        .withPayload(jsonPayload)
        .withInvocationType(InvocationType.RequestResponse)
        .withLogType(LogType.Tail);

InvokeResult result = client.invoke(request);

The log result contains the message 'done' so I believe the code executed without errors. 日志结果包含消息“ done”(完成),因此我相信代码执行无误。 However, I can't see how to get the output from the SQL query. 但是,我看不到如何从SQL查询获取输出。 Assuming I pass SELECT * FROM user WHERE Username = 'My User' , how do I get user details in the Java code? 假设我通过SELECT * FROM user WHERE Username = 'My User' ,如何在Java代码中获取用户详细信息?

为了获得作为JSON的结果回调,所需要的是:

new String(result.getPayload().array())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM