Lambda函数没有正确检测表



我试图在AWS Cloud Quest的机器学习路径中完成实验室,但得到一个错误"你的Lambda函数没有正确检测表">

我尝试了其他一些方法,但它不起作用,似乎我只需要取消注释几行代码并将资源从FIELDS更改为TABLES,但它没有通过测试,我卡住了。

我做错了什么?也许你们中有人完成了这个实验?

我的代码

import json
import logging
import boto3
from trp import Document
from urllib.parse import unquote_plus
logger = logging.getLogger()
logger.setLevel(logging.INFO)
s3 = boto3.client('s3')
output_key = "output/textract_response.json"

def lambda_handler(event, context):
logger.info(event)
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = unquote_plus(record['s3']['object']['key'])
textract = boto3.client('textract')
try:
response = textract.analyze_document(  
Document={                         
'S3Object': {
'Bucket': bucket,
'Name': key
}
},
FeatureTypes=['TABLES',  # FeatureTypes is a list of the types of analysis to perform.
])                            



doc = Document(response)  
for page in doc.pages:
print("Fields:")
for field in page.form.fields:
print("Key: {}, Value: {}".format(field.key, field.value))
print("nSearch Fields:")
key = "address"
fields = page.form.searchFieldsByKey(key)
for field in fields:
print("Key: {}, Value: {}".format(field.key, field.value))
for page in doc.pages:
print("nTable details:")
for table in page.tables:
for r, row in enumerate(table.rows):
for c, cell in enumerate(row.cells):
print("Table[{}][{}] = {}".format(r, c, cell.text))
return_result = {"Status": "Success"}
# Finally the response file will be written in the S3 bucket output folder.
s3.put_object(
Bucket=bucket,
Key=output_key,
Body=json.dumps(response, indent=4)
)
return return_result
except Exception as error:
return {"Status": "Failed", "Reason": json.dumps(error, default=str)}

我在AWS工作(销售,不是技术!),也遇到过同样的问题。我提出了一个支持票来检查验证服务是否正常工作。我也遇到了同样的验证失败问题,尽管cloudwatch日志显示了表数据——确认lambda代码确实是正确的。我们的支持团队注意到"从文档中提取文本"的分配验证有一个问题。实验室现在已经修好了。我刚刚又做了一次实验,验证成功了,所以现在实验室已经完成了。你现在可能想再试一次。希望这对你有所帮助。:)

lambda test事件是否生成表的详细信息?如果你的缩进是正确的,我看不出有什么明显的东西。

  1. 再次上传form.png到输入文件夹
  2. 查看cloudwatchloggroups/aws/lambda/labfunction>>>将新的。png文件添加到输入文件夹后保存的最新流。
  3. validations检查text_response。

最新更新