【问题标题】:AWS Lambda Function Handler Error Says There Is Not Enough Values To UnpackAWS Lambda 函数处理程序错误表示没有足够的值来解包
【发布时间】:2021-03-26 03:44:27
【问题描述】:

我有一个由 SQS 消息触发的 Lambda 函数(在 Boto3 中创建)。 Lambda 函数旨在获取上传到 S3 的对象并使用 AWS Transcribe 处理它们。正在触发 Lambda 函数,但我收到以下错误:

{
  "errorMessage": "Bad handler 'lambda_handler': not enough values to unpack (expected 2, got 1)",
  "errorType": "Runtime.MalformedHandlerName"
}

Function Logs
START RequestId: e6080a7f-b5b7-4995-a469-351c144bb93e Version: $LATEST
[ERROR] Runtime.MalformedHandlerName: Bad handler 'lambda_handler': not enough values to unpack (expected 2, got 1)
END RequestId: e6080a7f-b5b7-4995-a469-351c144bb93e
REPORT RequestId: e6080a7f-b5b7-4995-a469-351c144bb93e  Duration: 1.64 ms   Billed Duration: 2 ms   Memory Size: 500 MB Max Memory Used: 50 MB

Request ID
e6080a7f-b5b7-4995-a469-351c144bb93e

这是我在 Boto3 中创建 Lambda 函数的地方:

response = l.create_function(
    FunctionName = lambda_name,
    Runtime = 'python3.7',
    Role = lambda_role,
    Handler = 'lambda_handler',
    Code = {
        'ZipFile': open('./transcribe.zip', 'rb').read()
    },
    Description = 'Function to parse content from SQS message and pass content to Transcribe.',
    Timeout = 123,
    MemorySize = 500,
    Publish = True,
    PackageType = 'Zip',
)

这就是 Lambda 函数在 AWS 控制台中的样子:

from __future__ import print_function
import time
import boto3

def lambda_handler(event, context):
    transcribe = boto3.client('transcribe')

    job_name = "testJob"
    job_uri = "https://my-bucket1729788.s3.eu-west-2.amazonaws.com/Audio3.wav"
    transcribe.start_transcription_job(
        TranscriptionJobName=job_name,
        Media={'MediaFileUri': job_uri},
        MediaFormat='wav',
        LanguageCode='en-US'
    )
    
    while True:
        status = transcribe.get_transcription_job(TranscriptionJobName=job_name)
        if status['TranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']:
            break
        print("Not ready yet...")
        time.sleep(5)
    print(status)

我真的不知道我哪里出错了,因为我没有发现文档特别有用,所以任何帮助都非常感谢。谢谢。

【问题讨论】:

    标签: amazon-web-services aws-lambda boto3


    【解决方案1】:

    当我尝试运行时,我的函数没有接收到上下文或事件:

    def lambda_handler(event, context):
    
        print("Event: {}".format(event))
        print("Context: {}".format(context))
    

    我需要将运行时设置中的“处理程序”设置从“lambda_handler”更改为“transcribe.lambda_handler”,因为 transcribe.py 是文件名。

    【讨论】:

      【解决方案2】:

      您的 Lambda 函数代码中没有名为 lambda_handler 的函数。请查看the documentation 了解 Python Lambda 函数。

      【讨论】:

      • 根据文档编辑以包含处理程序,但仍然给我同样的错误。
      【解决方案3】:

      我认为问题在于您的处理程序路径未在 create 函数调用中正确设置。它应该类似于<function_name>.<handler>,请注意路径中的.。你在帖子中只有lambda_handler,没有.

      【讨论】:

        猜你喜欢
        • 2021-12-15
        • 2021-12-12
        • 2021-10-03
        • 1970-01-01
        • 1970-01-01
        • 2021-09-12
        • 1970-01-01
        • 1970-01-01
        • 2018-01-26
        相关资源
        最近更新 更多