嗨,我正在尝试使用AWS Rekognition -> Lambda -> AWS -> Bubble.io,我想传递一个图像base64代码来处理图像识别。
以下是lambda代码:
import json
import boto3
import base64
def lambda_handler(event, context):
def detect_labels():
# 1. create a client object, to connect to rekognition
client=boto3.client('rekognition')
image = base64.b64decode(event['face'])
# 4. call Rekognition, store result in 'response'
response = client.detect_labels(
Image={
'Bytes': image
},
MaxLabels=20,
)
#6. Return response from function
return response
# Call detect_labels
response = detect_labels()
# Return results to API gateway
return {
'statusCode': 200,
'body': json.dumps(response)
}如果我在lambda测试中使用config测试它:
{
"face": "<imgbase64codehere>"
}它工作良好,并返回成功信息。但是,我在Bubble.io 设置img中设置了相同的内容。这不管用。
我检查云表,错误是:
[ERROR] KeyError: 'face'
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 30, in lambda_handler
response = detect_labels()
File "/var/task/lambda_function.py", line 14, in detect_labels
image = base64.b64decode(event['face'])
[ERROR] KeyError: 'face' Traceback (most recent call last): File "/var/task/lambda_function.py", line 30, in lambda_handler response = detect_labels() File "/var/task/lambda_function.py", line 14, in detect_labels image = base64.b64decode(event['face'])我确信没有连接问题(如果我不使用JSON,它工作得很好),那么我在设置中做错了什么呢?谢谢你提前提供帮助
发布于 2022-06-19 19:13:04
在您的测试中,您只发送带有face的JSON请求的输入。
看起来,您安装的实现使用了Amazon网关。如果您这样做,您的Lambda函数可能会以不同的格式接收事件,这取决于您如何实现API网关集成。
Lambda开发人员指南有一个JSON格式的示例。您可能希望访问body属性。
https://stackoverflow.com/questions/72673776
复制相似问题