如何在无服务器离线中引用子目录中的处理程序?

How to reference handlers in sub-directories in serverless-offline?

Windows 10 64bits

Node v12.16.3

Serverless 1.71.3

serverless-offline 6.1.7

目录:

root:
- package.json
- /sub
-- __init__.py
-- sub_handler.py
- ...
- handler.py
- serverless.yml

您好,我目前正在尝试使用无服务器离线在本地测试两个 lambda 函数。 它适用于根目录中的处理程序 但似乎 serverless-offline 无法引用子目录中的其他处理程序..

如何在子目录中引用处理程序?

PS:此配置在部署到 AWS LAMBDA 时有效。我可以 post 两条路。

当我尝试 post hello2:

时出错

[offline] Loading handler... (C:\Users\my_user\Desktop\serverless-offline\sub\sub_handler) Traceback (most recent call last):
File C:\Users\my_user\Desktop\serverless-offline\node_modules\serverless-offline\dist\lambda\handler-runner\python-runner\invoke.py", line 75, in

    module = import_module(args.handler_path.replace('/', '.'))
File "C:\Users\my_user\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py",

line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import

File "<frozen importlib._bootstrap>", line 971, in _find_and_load   
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked

ModuleNotFoundError: No module named 'sub\sub_handler'

serverless.yml:

service: sls-offline-test    
provider:
  name: aws
  runtime: python3.6
  memorySize: 256
  stage: ${opt:stage, 'dev'}
  region: us-east-1
  environment:
    STAGE: ${self:provider.stage}    
functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: POST
  hello2:
    handler: sub/sub_handler.hello2
    events:
      - http:
          path: 'hello2'
          method: POST    
package:
  individually: true    
  include:
    - sub/**
plugins:
  - serverless-offline

最近遇到同样的问题,更新了serverless-offline插件的版本,解决了