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": []
}
Advertisement
Answer
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.