Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda Function Handler Error Says There Is Not Enough Values To Unpack

I have a Lambda function (created in Boto3) which is triggered by an SQS message. The Lambda function is meant to take the objects uploaded to S3 and process them with AWS Transcribe. The Lambda function is being triggered but I'm receiving the following error:

{
  "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

This is where I create my Lambda function in Boto3:

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',
)

And this is what the Lambda function looks like in AWS console:

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)

I'm really not sure where I'm going wrong as I don't find the documentation particularly helpful, so any help is appreciated. Thanks.

like image 810
Jamie Avatar asked Mar 11 '26 18:03

Jamie


1 Answers

My function wasn't receiving either the context or the event when I tried running:

def lambda_handler(event, context):

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

I needed to change the 'Handler' setting on runtime settings from 'lambda_handler' to 'transcribe.lambda_handler', as transcribe.py was the name of the file.

like image 85
Jamie Avatar answered Mar 13 '26 13:03

Jamie