AWS Lambda 函数处理程序错误表示没有足够的值来解压

Jam*_*mie 3 amazon-web-services boto3 aws-lambda

我有一个由 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
Run Code Online (Sandbox Code Playgroud)

这是我在 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',
)
Run Code Online (Sandbox Code Playgroud)

这就是 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)
Run Code Online (Sandbox Code Playgroud)

我真的不确定我哪里出错了,因为我没有发现文档特别有帮助,所以任何帮助都是值得赞赏的。谢谢。

Jam*_*mie 6

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

def lambda_handler(event, context):

    print("Event: {}".format(event))
    print("Context: {}".format(context))
Run Code Online (Sandbox Code Playgroud)

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