2

我是无服务器框架的新手,我正在尝试使用 serverless-offline,我的代码在 AWS 上部署时运行良好,但在本地抛出未找到模块的错误。编写时相同的代码是 hello-world 的 javasript 它工作得很好

这是我的 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

这是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

sls offline

输出是

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

但是什么时候http://localhost:3000/hello-world被调用

输出是


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

4

0 回答 0