我在 python 中有一个无服务器代码。我正在使用 serverless-python-requirements:^4.3.0 将其部署到 AWS lambda 中。我的代码在与其自身相同的目录中导入另一个 python 文件,这会引发错误。
无服务器.yml:
functions:
hello:
handler: functions/pleasework.handle_event
memorySize: 128
tags:
Name: HelloWorld
Environment: Ops
package:
include:
- functions/pleasework
- functions/__init__.py
- functions/config
(venv) ➜ functions git:(master) ✗ ls
__init__.py boto_client_provider.py config.py handler.py sns_publish.py
__pycache__ cloudtrail_handler.py glue_handler.py pleasework.py
如您所见,pleasework.py 和 config 在同一个文件夹中,但是当我在 pleasework 中导入配置时出现错误:
{
"errorMessage": "Unable to import module 'functions/pleasework': No module named 'config'",
"errorType": "Runtime.ImportModuleError"
}
我为此苦苦挣扎了几天,并认为我缺少一些基本的东西。
import boto3
import config
def handle_event(event, context):
print('lol: ')