2

I am new to serverless framework , I am trying to use serverless-offline , my code works fine when I deploy it on AWS but locally is throw error of no module found. the same code when written is javasript for hello-world it works just fine

this is my handler.py

import json
import datetime


def endpoint(event, context):
    body = {
        "message": "Hello, you called the ping"
    }

    response = {
        "statusCode": 200,
        "body": json.dumps(body)
    }

    return response

this is yml


service: hello-world-offline

provider:
  name: aws
  runtime: python3.6
  region: eu-west-1
  profile: default
  memorySize: 256 # optional, in MB, default is 1024
  stage: dev

plugins:
  - serverless-offline


functions:
  hello-world:
    handler: handler.endpoint 
    events:
      - http:
          path: hello-world
          method: get

after sls offline

the output is

Serverless: Starting Offline: dev/eu-west-1.

Serverless: Routes for hello-world:
Serverless: GET /hello-world
Serverless: POST /{apiVersion}/functions/hello-world-offline-dev-hello-world/invocations

Serverless: Offline [HTTP] listening on http://localhost:3000
Serverless: Enter "rp" to replay the last request

but when http://localhost:3000/hello-world is called

the output is


Serverless: GET /hello-world (λ: hello-world)
Serverless: Failure: internal/modules/cjs/loader.js:798
    throw err;
    ^

Error: Cannot find module '/home/imran/serverless projects/hello-world-offline/invoke'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:795:15)
    at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1287:46)
    at Function.Module._load (internal/modules/cjs/loader.js:688:27)
    at Function.Module.runMain (pkg/prelude/bootstrap.js:1316:12)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

undefined

Imran Khan
  • 61
  • 3
  • I am getting the same error on my next js app trying to deploy on firebase cloud function – rak1n Jan 25 '20 at 00:27
  • I just used the serverless.yml with the handler.py you provided and it is working for me. Do you still have the problem ? I am using serverless-offline 5.12.1 ... If you type "python" from a command line what version do you get ? I am running within a python3.7 virtual environment. – Christophe Feb 08 '20 at 08:45

0 Answers0