errorMessage": "Unable to import module 'handler'

I am trying to get started with the serverless framework. I followed the AWS quick start guide and instead of Nodejs, i am using python. However, am getting the following error while trying to invoke the function.

{
    "errorMessage": "Unable to import module 'handler'"
}
--------------------------------------------------------------------
START RequestId: 630c20c2-573d-11e7-9012-39b5c641a4d4 Version: $LATEST
Unable to import module 'handler': No module named handler

END RequestId: 630c20c2-573d-11e7-9012-39b5c641a4d4
REPORT RequestId: 630c20c2-573d-11e7-9012-39b5c641a4d4	Duration: 0.22 ms	Billed Duration: 100 ms 	Memory Size: 1024 MB	Max Memory Used: 18 MB	


 
  Error --------------------------------------------------
 
  Invoked function failed
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless
 
  Your Environment Information -----------------------------
     OS:                     linux
     Node Version:           6.11.0
     Serverless Version:     1.15.3

But, If I manually edit the function from the lambda editor and invoke it, it is not throwing any error. It is throwing an error only when invoking through the serverless framework.

Have you defined the right runtime for your service? It sounds like the service is trying to import your Python code as a Node module…

also getting these all of sudden today, checked everything, deleted node_modules etc etc etc .

START RequestId: bbf91003-3514-11e8-a562-0b564eacadc5 Version: $LATEST

18:53:01
Unable to import module ‘general/userStoreInfo’: Error

hours now trying to solve this

2 Likes

Any ideas how to resolve this?
When running sls deploy -v the function gets created in Lambda with the expected environment variables. When I execute the Lambda function I get:

{
  "errorMessage": "Unable to import module 'handler'"
}

Here’s my code:
handler.py

import os


def hello(event, context):
    FN = os.environ('FIRST_NAME')
    print('First Name: ', FN)

serverless.yml

service: python-env-vars-ex

provider:
  name: aws
  runtime: python3.6
  profile: serverless-admin
  region: ap-southeast-2
  environment:
    var1: "val1"
    var2: "val2"
    FIRST_NAME: "Ultradox"

functions:
  hello:
    handler: handler.hello