AWS Lambda function handler missing
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": []
}
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.
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'
},
]
},
]
)