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

问题描述 投票:0回答:1

Windows 10 64位

节点v12.16.3

无服务器1.71.3

无服务器离线6.1.7

目录

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

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

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

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

当我尝试发布hello2时出错:

[offline]加载处理程序...(C:\ Users \ my_user \ Desktop \ serverless-offline \ sub \ sub_handler)追溯(最近一次通话):文件C:\ Users \ my_user \ Desktop \ serverless-offline \ node_modules \ serverless-offline \ dist \ lambda \ handler-runner \ python-runner \ invoke.py”,第75行,在>

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

第126行,在import_module中返回_bootstrap._gcd_import(name [level:],包,级别)_gcd_import中的文件“”,第994行

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

ModuleNotFoundError:没有名为'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

Windows 10 64位节点v12.16.3无服务器1.71.3无服务器离线6.1.7目录:根目录:-package.json-/ sub-__init__.py-sub_handler.py-...-handler.py-无服务器.yml ...

python serverless-framework serverless-offline
1个回答
0
投票

最近,我遇到了同样的问题,我更新了无服务器离线插件的版本并为我解决了问题

© www.soinside.com 2019 - 2024. All rights reserved.