Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 仅使用AWS Lambda加载本地模块时出现故障_Python_Python 3.x_Amazon Web Services_Aws Lambda - Fatal编程技术网

Python 仅使用AWS Lambda加载本地模块时出现故障

Python 仅使用AWS Lambda加载本地模块时出现故障,python,python-3.x,amazon-web-services,aws-lambda,Python,Python 3.x,Amazon Web Services,Aws Lambda,应用程序结构: . ├── Makefile ├── Pipfile ├── Pipfile.lock ├── README.md ├── template.yaml ├── tests │ ├── __init__.py │ └── unit │ └── lambda_application │ ├── test_handler.py │ └── test_parent_child_class.py └── lambda_applic

应用程序结构:

.
├── Makefile
├── Pipfile
├── Pipfile.lock
├── README.md
├── template.yaml
├── tests
│   ├── __init__.py
│   └── unit
│       └── lambda_application
│           ├── test_handler.py
│           └── test_parent_child_class.py
└── lambda_application
    ├── __init__.py
    ├── first_child_class.py
    ├── lambda_function.py
    ├── second_child_class.py
    ├── requirements.txt
    └── parent_class.py

4 directories, 14 files
来自lambda_function.py的代码示例:

import os
import json
from hashlib import sha256
import boto3
from requests import Session
from .first_child_class import FirstChildClass


def lambda_handler(event, context):
    # Do some stuff.
按原样,我会收到错误消息“无法导入模块‘lambda_函数’”,但如果我注释掉上次导入,“from.first_child_class import FirstChildClass”,它就能够通过该部分并得到错误,即我没有为该类加载模块

我似乎只有在lambci/lambda:python3.7 docker映像中运行它时,以及在AWS上部署时,才会出现此错误。我所有的测试都通过了,它可以毫无问题地导入模块

\uuuu init\uuuuu.py
文件中是否有我应该加载/设置的内容


编辑我更改了一些文件的名称,将其发布到此处。

您在此处使用的是
相对导入
,如果您正在执行的代码位于模块中,则该导入会起作用。但是,由于代码不是作为模块执行的,因此AWS Lambda会失败

本地快速运行时出现以下错误:

PYTHON 3.6
我的导入从lib.first\u child\u class import FirstChildClass

变成了
,现在更有意义了。我现在确定我需要如何修复它。如果答案解决了你的问题,请考虑把它标记为正确答案。
Traceback (most recent call last):
  File "lambda_function.py", line 4, in <module>
    from .first_child_class import FirstChildClass
ModuleNotFoundError: No module named '__main__.first_child_class'; '__main__' is not a package
.
├── Makefile
├── Pipfile
├── Pipfile.lock
├── README.md
├── template.yaml
├── tests
│   ├── __init__.py
│   └── unit
│       └── lambda_application
│           ├── test_handler.py
│           └── test_parent_child_class.py
└── lambda_application
    ├── __init__.py
    └── lib
        ├── first_child_class.py
        ├── second_child_class.py
        └── parent_class.py
    ├── lambda_function.py
    └── requirements.txt