本文介绍了尝试读取AWS SNS消息时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将Rekognition发送的消息返回给SNS,但是我在CloudWatch中收到此错误:

I need to return the message sent by Rekognition to SNS but I get this error in CloudWatch:

代码:

def detect_labels(bucket, key):
    response = rekognition.start_label_detection(
        Video = {
            "S3Object": {
                "Bucket": BUCKET,
                "Name": KEY
            }
        },
        NotificationChannel = {
            "SNSTopicArn": TOPIC_ARN,
            "RoleArn": ROLE_ARN
        }
    )

    return response

def lambda_handler(event, context):
    reko_response = detect_labels(BUCKET, KEY)
    message = event["Records"][0]["Sns"]["Message"]
    return message

这是在AWS中实现Rekognition存储视频的正确方法吗带有python的Lambda我没有找到任何示例。

And is this the correct way of implementing Rekognition stored video in AWS Lambda with python I didn't find any examples on it.

更新:

我的应用所需的步骤


  1. 在前端,用户使用API​​网关触发lambda函数,其中
    将文件发送到s3

  2. 文件到达时触发相同的lambda函数,以应用视频
    识别并将jobId发送到SNS

  3. 当SNS收到消息时,触发相同的lambda函数来获取
    标签数据并将数据通过API网关返回给用户


推荐答案

您的函数正在调用 rekognition。)(大概您已经创建了 rekognition 客户端

Your function is calling rekognition.start_label_detection() (and presumably you have created the rekognition client in code not shown).

此API调用开始对视频进行标签检测。完成后,它将向指定的SNS主题发布消息。您可以将Lambda函数连接到SNS,以在完成时检索标签检测的详细信息。

This API call starts label detection on a video. When it is finished, it will publish a message to the given SNS topic. You can connect a Lambda function to SNS to retrieve the details of the label detection when it is finished.

但是,您的代码混淆了操作的顺序。相反,您应该执行以下操作:

However, your code is getting the order of operations mixed up. Instead, you should be doing the following:


  • 某些事情(可能不是Lambda函数)应调用 start_label_detection() 开始扫描视频。这可能需要几分钟。

  • 应该配置Lambda函数以在SNS主题收到消息时触发。

  • 然后传递Lambda函数邮件的副本,可用于调用 get_label_detection()来检索扫描的详细信息。

  • Something (probably not a Lambda function) should call start_label_detection() to begin the process of scanning the video. This can take several minutes.
  • A Lambda function should be configured to trigger when the SNS topic receives a message.
  • The Lambda function is then passed a copy of the message, which can be used to call get_label_detection() to retrieve the details of the scan.

因此,第一步是将初始 start_label_detection()请求与检索结果的代码分开。然后,修改Lambda函数以通过 get_label_detection()检索结果并处理结果。

So, your first step is to separate the initial start_label_detection() request from the code that retrieves the results. Then, modify the Lambda function to retrieve the results via get_label_detection() and process the results.

这篇关于尝试读取AWS SNS消息时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 17:13