1

I created the following lambda function and its given me the following error. I am new to Python and I dont think there's anything missing in the function. can someone please help to make this function work? Thanks

import logging
import json
import boto3

client = boto3.client('workspaces')

def handler(event, context):
    response = create_workspace()
    return event
    
def create_workspace():    
    response = client.create_workspaces(
        Workspaces=[
            {
                'DirectoryId': 'd-9767328a34',
                'UserName': 'Ken',
                'BundleId': 'wsb-6cdbk8901',
                'WorkspaceProperties': {
                    'RunningMode': 'AUTO_STOP'
                },
                'Tags': [
                    {
                        'Key': 'Name',
                        'Value': 'CallCentreProvisioned'
                    },
                ]
            },
        ]
    )

Execution result

{
  "errorMessage": "Handler 'lambda_handler' missing on module 'lambda_function'",
  "errorType": "Runtime.HandlerNotFound",
  "requestId": "a09fd219-b262-4226-a04b-4d26c1b7281f",
  "stackTrace": []
}
2
  • 1
    The name of the handler in the function config needs to match the function name in the code. Looks like handler != lambda_handler. Commented Jan 17, 2022 at 13:38
  • Unrelated, but a Lambda function handler typically returns a packaged response, not the the original event that triggered the Lambda function. Commented Jan 17, 2022 at 14:54

2 Answers 2

3

Very simple. Rename handler to lambda_handler, or change your lambda configuration to use the handler called handler rather than lambda_handler. There were comments that mentioned this, but no simple answer given.

There is no good reason to nest the function as the other answer seems to suggest.

Sign up to request clarification or add additional context in comments.

Comments

1

You should have this syntax:

def handler_name(event, context): 
    // paste your code here
    return some_value

I think you should be like this. And look at the Naming paragraph.:

import logging
import json
import boto3

def lambda_handler(event, context):

    client = boto3.client('workspaces')
    
    response = create_workspace()
    return event
    
    def create_workspace():    
        response = client.create_workspaces(
            Workspaces=[
                {
                    'DirectoryId': 'd-9767328a34',
                    'UserName': 'Ken',
                    'BundleId': 'wsb-6cdbk8901',
                    'WorkspaceProperties': {
                        'RunningMode': 'AUTO_STOP'
                    },
                    'Tags': [
                        {
                            'Key': 'Name',
                            'Value': 'CallCentreProvisioned'
                        },
                    ]
                },
            ]
        )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.