AWS Lambda errorMessage: Handler 'handler' missing on module 'main'"

1,859 views
Skip to first unread message

Alan Ribeiro

unread,
Apr 10, 2018, 5:16:15 PM4/10/18
to Terraform
I have a problem with deploying a code on AWS Lambda, the information in my environment is:

The name of my folder is TestCassandra
The name of my file is main.py
The name of my handler is main.handler
The Runtime of my code is Python 3.6

MY CODE:

#!/usr/bin/python
# -*- coding: latin-1 -*-

import os
import subprocess

def main.handler(event, context):
def rodando(processo):
     try:
         subprocess.check_output('ps ax | grep {}| grep -v grep \
'.format(processo),shell=True)
     except Exception:
         return 0
     return 1

if rodando('+service'):
     print ('up!')
else:
     print ('down')
 
I'm taking the error:

Response:
{
  "errorMessage": "Handler 'handler' missing on module 'main'"
}

Can someone help me or know how to solve it?

Regard,

Stephen Eilert

unread,
Apr 10, 2018, 5:46:03 PM4/10/18
to Terraform

def main.handler(event, context):

The Python formatting seems to have gotten lost on the email, but your handler code doesn't seem to have anything inside it. This is definitely not a Terraform issue. I would suggest starting  with some python examples for AWS Lambda and then going from there.

Also, don't expect to have a full environment to be able to shell out and run Unix commands in a Lambda function. It is not supposed to be used that way. Nor it will return any meaningful results, as whatever host this is running at is not the same as your Cassandra node.


— Stephen

Alan Ribeiro

unread,
Apr 10, 2018, 5:55:41 PM4/10/18
to Terraform

Hello Stephen, are you Brazilian? Could I send you an email or call in the hangouts to understand a little more? thank you!
Reply all
Reply to author
Forward
0 new messages