FIX ERROR – AWS Lambda Python: "main() takes 0 positional arguments but 2 were given"

When trying to execute the Lambda Python function, the following error occurs:

{
  "errorMessage": "main() takes 0 positional arguments but 2 were given",
  "errorType": "TypeError",
  "stackTrace": [
    "  File \"/var/runtime/bootstrap.py\", line 131, in handle_event_request\n    response = request_handler(event, lambda_context)\n"
  ]
}

 

Solution:

From the message, we see that we use the "main" function as a handler, which has no incoming arguments.

def main():

 

And to run, you need a handler of 2 arguments "event" and "context", so you need to bring the function declaration to the following form:

def main(event, context):

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments