【问题标题】:AWS Textract does not run callback in error free run of analyzeDocumentAWS Textract 在analyzeDocument 的无错误运行中不运行回调
【发布时间】:2021-11-06 15:39:08
【问题描述】:

目前

我正在尝试让 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 取回数据。看来我无法让回调完全正常工作。奇怪的是,如果有错误,例如我的配置错误,回调的错误处理会打印日志和“正在分析...”日志,但是如果没有错误,回调中的任何日志都不会打印。

当前日志:

Parse as document...
Finished parsing as document.

预期/期望的日志:

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

请帮忙!

注意事项

  • 我正在为该 Lambda 使用一个角色,该角色允许它访问 Textract。
  • 无论是否包含HumanLoopConfig 设置,我都会得到相同的结果。

【问题讨论】:

    标签: aws-lambda aws-sdk-js amazon-textract


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-21
      • 2019-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 2022-11-25
      • 1970-01-01
      相关资源
      最近更新 更多