AWS Textract 不会 运行 在 analyzeDocument 的无错误 运行 中回调

AWS Textract does not run callback in error free run of analyzeDocument

当前

我正在尝试让 AWS Textract 在 Lambda 函数上运行,并且正在关注 https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Textract.html#analyzeDocument-property

上的文档

我的 Lambda 代码:

"use strict";

const AWS = require("aws-sdk");

exports.handler = async (event) => {
  let params = JSON.parse(event.body);
  console.log("Parse as document...");
  let textract = new AWS.Textract();
  let doc = params["doc"];
  let config = {
    Document: {
      Bytes: doc,
    }
  };
  textract.analyzeDocument(config, function (err, data) {
    console.log("analyzing...");  //<-- nothing logged to console if no error
    if (err) {
      console.log(err, err.stack);
    }
    // an error occurred
    else {
      console.log("data:" + JSON.stringfy(data));  //<-- nothing logged to console if no error
    } // successful response
  });
  console.log("Finished parsing as document.");
};

问题

我无法从 Textract 取回数据。看来我无法让回调完全正常工作。奇怪的是,如果有错误,例如我的配置是错误的,回调的错误处理将打印日志和“正在分析...”日志,但没有错误,none 回调打印中的日志。

当前日志:

Parse as document...
Finished parsing as document.

预期/期望日志:

Parse as document...
analyzing...
data:{textract output}
Finished parsing as document.

请帮忙!

注释

已解决,显然我需要设置一个承诺:

 let data = await textract.analyzeDocument(config).promise()
 console.log("data:"+data );
 console.log("Finished parsing as document.")