Python:AWS Lambda&#34; errorMessage&#34;:&#34;无法导入模块&#39; <module_name>&#39;&#34;&#34;

时间:2017-03-08 11:19:50

标签: python amazon-web-services aws-lambda

我想知道为什么我会收到此错误。

这些是我所做的步骤:

0)我在lambda_handler脚本

中创建了getUserInfo.py函数

1)我创建了一个部署包,我的getUserInfo.py位于顶层 enter image description here

2)我更改了该目录中的权限: chmod -R 755 deployment_package,导致:

enter image description here

3)我认为压缩文件夹的内容并将其命名为getUserInfo.zip

4)然后我开始在AWS中创建lambda函数,确保将handler设置为getUserInfo.lambda_handler

enter image description here

5)当我运行并测试该功能时,似乎它没有检测到我的getUserInfo.py模块。

enter image description here

注意:这是在Python 2.7中,我也试过包括__init.py__,但它也没有用。有什么想法吗?

编辑:

这是getUserInfo.py

中的代码
from firebase import Firebase

def lambda_handler(event, context):
    f = Firebase('https://unicon-1d994.firebaseio.com/Users')
    return f.get()

Firebase library是适用于Firebase的REST API的包装器。

这是unzip -l getUserInfo.zip

的输出
Archive:  getUserInfo.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  03-08-2017 22:17   __init__.py
        0  03-08-2017 22:17   __MACOSX/
      546  03-08-2017 22:17   __MACOSX/.___init__.py
      150  03-08-2017 21:18   getUserInfo.py
      530  03-08-2017 21:18   __MACOSX/._getUserInfo.py
        0  03-08-2017 20:16   requests/
     2197  03-08-2017 20:16   requests/__init__.py
     2964  03-08-2017 20:16   requests/__init__.pyc
     1096  03-08-2017 20:16   requests/_internal_utils.py
     1649  03-08-2017 20:16   requests/_internal_utils.pyc
    19727  03-08-2017 20:16   requests/adapters.py
    18990  03-08-2017 20:16   requests/adapters.pyc
     5987  03-08-2017 20:16   requests/api.py
     7158  03-08-2017 20:16   requests/api.pyc
     9541  03-08-2017 20:16   requests/auth.py
    10774  03-08-2017 20:16   requests/auth.pyc
   348799  03-08-2017 20:16   requests/cacert.pem
      625  03-08-2017 20:16   requests/certs.py
      983  03-08-2017 20:16   requests/certs.pyc
     1627  03-08-2017 20:16   requests/compat.py
     1877  03-08-2017 20:16   requests/compat.pyc
    18291  03-08-2017 20:16   requests/cookies.py
    24424  03-08-2017 20:16   requests/cookies.pyc
     2976  03-08-2017 20:16   requests/exceptions.py
     7495  03-08-2017 20:16   requests/exceptions.pyc
      767  03-08-2017 20:16   requests/hooks.py
     1387  03-08-2017 20:16   requests/hooks.pyc
    33067  03-08-2017 20:16   requests/models.py
    29653  03-08-2017 20:16   requests/models.pyc
        0  03-08-2017 20:16   requests/packages/
     1384  03-08-2017 20:16   requests/packages/__init__.py
     1677  03-08-2017 20:16   requests/packages/__init__.pyc
        0  03-08-2017 20:16   requests/packages/chardet/
     1295  03-08-2017 20:16   requests/packages/chardet/__init__.py
      933  03-08-2017 20:16   requests/packages/chardet/__init__.pyc
    82594  03-08-2017 20:16   requests/packages/chardet/big5freq.py
   113848  03-08-2017 20:16   requests/packages/chardet/big5freq.pyc
     1684  03-08-2017 20:16   requests/packages/chardet/big5prober.py
     1364  03-08-2017 20:16   requests/packages/chardet/big5prober.pyc
     2504  03-08-2017 20:16   requests/packages/chardet/chardetect.py
     3175  03-08-2017 20:16   requests/packages/chardet/chardetect.pyc
     9226  03-08-2017 20:16   requests/packages/chardet/chardistribution.py
     9293  03-08-2017 20:16   requests/packages/chardet/chardistribution.pyc
     3791  03-08-2017 20:16   requests/packages/chardet/charsetgroupprober.py
     3016  03-08-2017 20:16   requests/packages/chardet/charsetgroupprober.pyc
     1902  03-08-2017 20:16   requests/packages/chardet/charsetprober.py
     2875  03-08-2017 20:16   requests/packages/chardet/charsetprober.pyc
     2318  03-08-2017 20:16   requests/packages/chardet/codingstatemachine.py
     2261  03-08-2017 20:16   requests/packages/chardet/codingstatemachine.pyc
     1157  03-08-2017 20:16   requests/packages/chardet/compat.py
      695  03-08-2017 20:16   requests/packages/chardet/compat.pyc
     1335  03-08-2017 20:16   requests/packages/chardet/constants.py
      400  03-08-2017 20:16   requests/packages/chardet/constants.pyc
     1782  03-08-2017 20:16   requests/packages/chardet/cp949prober.py
     1372  03-08-2017 20:16   requests/packages/chardet/cp949prober.pyc
     3187  03-08-2017 20:16   requests/packages/chardet/escprober.py
     2845  03-08-2017 20:16   requests/packages/chardet/escprober.pyc
     7839  03-08-2017 20:16   requests/packages/chardet/escsm.py
     7372  03-08-2017 20:16   requests/packages/chardet/escsm.pyc
     3678  03-08-2017 20:16   requests/packages/chardet/eucjpprober.py
     3254  03-08-2017 20:16   requests/packages/chardet/eucjpprober.pyc
    45978  03-08-2017 20:16   requests/packages/chardet/euckrfreq.py
    88839  03-08-2017 20:16   requests/packages/chardet/euckrfreq.pyc
     1675  03-08-2017 20:16   requests/packages/chardet/euckrprober.py
     1373  03-08-2017 20:16   requests/packages/chardet/euckrprober.pyc
    34872  03-08-2017 20:16   requests/packages/chardet/euctwfreq.py
    61237  03-08-2017 20:16   requests/packages/chardet/euctwfreq.pyc
     1676  03-08-2017 20:16   requests/packages/chardet/euctwprober.py
     1373  03-08-2017 20:16   requests/packages/chardet/euctwprober.pyc
    36011  03-08-2017 20:16   requests/packages/chardet/gb2312freq.py
    68855  03-08-2017 20:16   requests/packages/chardet/gb2312freq.pyc
     1681  03-08-2017 20:16   requests/packages/chardet/gb2312prober.py
     1380  03-08-2017 20:16   requests/packages/chardet/gb2312prober.pyc
    13359  03-08-2017 20:16   requests/packages/chardet/hebrewprober.py
     4084  03-08-2017 20:16   requests/packages/chardet/hebrewprober.pyc
    47315  03-08-2017 20:16   requests/packages/chardet/jisfreq.py
    84071  03-08-2017 20:16   requests/packages/chardet/jisfreq.pyc
    19348  03-08-2017 20:16   requests/packages/chardet/jpcntx.py
    26007  03-08-2017 20:16   requests/packages/chardet/jpcntx.pyc
    12784  03-08-2017 20:16   requests/packages/chardet/langbulgarianmodel.py
    24953  03-08-2017 20:16   requests/packages/chardet/langbulgarianmodel.pyc
    17725  03-08-2017 20:16   requests/packages/chardet/langcyrillicmodel.py
    30635  03-08-2017 20:16   requests/packages/chardet/langcyrillicmodel.pyc
    12628  03-08-2017 20:16   requests/packages/chardet/langgreekmodel.py
    24640  03-08-2017 20:16   requests/packages/chardet/langgreekmodel.pyc
    11318  03-08-2017 20:16   requests/packages/chardet/langhebrewmodel.py
    23460  03-08-2017 20:16   requests/packages/chardet/langhebrewmodel.pyc
    12536  03-08-2017 20:16   requests/packages/chardet/langhungarianmodel.py
    24937  03-08-2017 20:16   requests/packages/chardet/langhungarianmodel.pyc
    11275  03-08-2017 20:16   requests/packages/chardet/langthaimodel.py
    23446  03-08-2017 20:16   requests/packages/chardet/langthaimodel.pyc
     5232  03-08-2017 20:16   requests/packages/chardet/latin1prober.py
     3926  03-08-2017 20:16   requests/packages/chardet/latin1prober.pyc
     3268  03-08-2017 20:16   requests/packages/chardet/mbcharsetprober.py
     2888  03-08-2017 20:16   requests/packages/chardet/mbcharsetprober.pyc
     1967  03-08-2017 20:16   requests/packages/chardet/mbcsgroupprober.py
     1450  03-08-2017 20:16   requests/packages/chardet/mbcsgroupprober.pyc
    19590  03-08-2017 20:16   requests/packages/chardet/mbcssm.py
    17729  03-08-2017 20:16   requests/packages/chardet/mbcssm.pyc
     4793  03-08-2017 20:16   requests/packages/chardet/sbcharsetprober.py
     3773  03-08-2017 20:16   requests/packages/chardet/sbcharsetprober.pyc
     3291  03-08-2017 20:16   requests/packages/chardet/sbcsgroupprober.py
     2135  03-08-2017 20:16   requests/packages/chardet/sbcsgroupprober.pyc
     3764  03-08-2017 20:16   requests/packages/chardet/sjisprober.py
     3281  03-08-2017 20:16   requests/packages/chardet/sjisprober.pyc
     6840  03-08-2017 20:16   requests/packages/chardet/universaldetector.py
     4538  03-08-2017 20:16   requests/packages/chardet/universaldetector.pyc
     2652  03-08-2017 20:16   requests/packages/chardet/utf8prober.py
     2671  03-08-2017 20:16   requests/packages/chardet/utf8prober.pyc
        0  03-08-2017 20:16   requests/packages/idna/
       20  03-08-2017 20:16   requests/packages/idna/__init__.py
      239  03-08-2017 20:16   requests/packages/idna/__init__.pyc
     3299  03-08-2017 20:16   requests/packages/idna/codec.py
     4585  03-08-2017 20:16   requests/packages/idna/codec.pyc
      232  03-08-2017 20:16   requests/packages/idna/compat.py
     1035  03-08-2017 20:16   requests/packages/idna/compat.pyc
    11352  03-08-2017 20:16   requests/packages/idna/core.py
    13018  03-08-2017 20:16   requests/packages/idna/core.pyc
    35172  03-08-2017 20:16   requests/packages/idna/idnadata.py
    38849  03-08-2017 20:16   requests/packages/idna/idnadata.pyc
     1521  03-08-2017 20:16   requests/packages/idna/intranges.py
     1890  03-08-2017 20:16   requests/packages/idna/intranges.pyc
   184931  03-08-2017 20:16   requests/packages/idna/uts46data.py
   277661  03-08-2017 20:16   requests/packages/idna/uts46data.pyc
        0  03-08-2017 20:16   requests/packages/urllib3/
     2853  03-08-2017 20:16   requests/packages/urllib3/__init__.py
     3377  03-08-2017 20:16   requests/packages/urllib3/__init__.pyc
    10553  03-08-2017 20:16   requests/packages/urllib3/_collections.py
    15328  03-08-2017 20:16   requests/packages/urllib3/_collections.pyc
    12709  03-08-2017 20:16   requests/packages/urllib3/connection.py
    11768  03-08-2017 20:16   requests/packages/urllib3/connection.pyc
    34940  03-08-2017 20:16   requests/packages/urllib3/connectionpool.py
    28543  03-08-2017 20:16   requests/packages/urllib3/connectionpool.pyc
        0  03-08-2017 20:16   requests/packages/urllib3/contrib/
        0  03-08-2017 20:16   requests/packages/urllib3/contrib/__init__.py
      215  03-08-2017 20:16   requests/packages/urllib3/contrib/__init__.pyc
    10865  03-08-2017 20:16   requests/packages/urllib3/contrib/appengine.py
    11388  03-08-2017 20:16   requests/packages/urllib3/contrib/appengine.pyc
     4478  03-08-2017 20:16   requests/packages/urllib3/contrib/ntlmpool.py
     4223  03-08-2017 20:16   requests/packages/urllib3/contrib/ntlmpool.pyc
    15139  03-08-2017 20:16   requests/packages/urllib3/contrib/pyopenssl.py
    19543  03-08-2017 20:16   requests/packages/urllib3/contrib/pyopenssl.pyc
     6195  03-08-2017 20:16   requests/packages/urllib3/contrib/socks.py
     6230  03-08-2017 20:16   requests/packages/urllib3/contrib/socks.pyc
     6603  03-08-2017 20:16   requests/packages/urllib3/exceptions.py
    15915  03-08-2017 20:16   requests/packages/urllib3/exceptions.pyc
     5943  03-08-2017 20:16   requests/packages/urllib3/fields.py
     7445  03-08-2017 20:16   requests/packages/urllib3/fields.pyc
     2321  03-08-2017 20:16   requests/packages/urllib3/filepost.py
     3719  03-08-2017 20:16   requests/packages/urllib3/filepost.pyc
        0  03-08-2017 20:16   requests/packages/urllib3/packages/
      109  03-08-2017 20:16   requests/packages/urllib3/packages/__init__.py
      378  03-08-2017 20:16   requests/packages/urllib3/packages/__init__.pyc
        0  03-08-2017 20:16   requests/packages/urllib3/packages/backports/
        0  03-08-2017 20:16   requests/packages/urllib3/packages/backports/__init__.py
      226  03-08-2017 20:16   requests/packages/urllib3/packages/backports/__init__.pyc
     1461  03-08-2017 20:16   requests/packages/urllib3/packages/backports/makefile.py
     1737  03-08-2017 20:16   requests/packages/urllib3/packages/backports/makefile.pyc
     8935  03-08-2017 20:16   requests/packages/urllib3/packages/ordered_dict.py
    11785  03-08-2017 20:16   requests/packages/urllib3/packages/ordered_dict.pyc
    30098  03-08-2017 20:16   requests/packages/urllib3/packages/six.py
    36813  03-08-2017 20:16   requests/packages/urllib3/packages/six.pyc
        0  03-08-2017 20:16   requests/packages/urllib3/packages/ssl_match_hostname/
      688  03-08-2017 20:16   requests/packages/urllib3/packages/ssl_match_hostname/__init__.py
      676  03-08-2017 20:16   requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyc
     5702  03-08-2017 20:16   requests/packages/urllib3/packages/ssl_match_hostname/_implementation.py
     4622  03-08-2017 20:16   requests/packages/urllib3/packages/ssl_match_hostname/_implementation.pyc
    13053  03-08-2017 20:16   requests/packages/urllib3/poolmanager.py
    13801  03-08-2017 20:16   requests/packages/urllib3/poolmanager.pyc
     5946  03-08-2017 20:16   requests/packages/urllib3/request.py
     6490  03-08-2017 20:16   requests/packages/urllib3/request.pyc
    22662  03-08-2017 20:16   requests/packages/urllib3/response.py
    21488  03-08-2017 20:16   requests/packages/urllib3/response.pyc
        0  03-08-2017 20:16   requests/packages/urllib3/util/
      994  03-08-2017 20:16   requests/packages/urllib3/util/__init__.py
     1287  03-08-2017 20:16   requests/packages/urllib3/util/__init__.pyc
     4237  03-08-2017 20:16   requests/packages/urllib3/util/connection.py
     4207  03-08-2017 20:16   requests/packages/urllib3/util/connection.pyc
     3704  03-08-2017 20:16   requests/packages/urllib3/util/request.py
     3980  03-08-2017 20:16   requests/packages/urllib3/util/request.pyc
     2343  03-08-2017 20:16   requests/packages/urllib3/util/response.py
     2521  03-08-2017 20:16   requests/packages/urllib3/util/response.pyc
    14123  03-08-2017 20:16   requests/packages/urllib3/util/retry.py
    15048  03-08-2017 20:16   requests/packages/urllib3/util/retry.pyc
    18836  03-08-2017 20:16   requests/packages/urllib3/util/selectors.py
    22165  03-08-2017 20:16   requests/packages/urllib3/util/selectors.pyc
    12046  03-08-2017 20:16   requests/packages/urllib3/util/ssl_.py
    11184  03-08-2017 20:16   requests/packages/urllib3/util/ssl_.pyc
     9757  03-08-2017 20:16   requests/packages/urllib3/util/timeout.py
    10332  03-08-2017 20:16   requests/packages/urllib3/util/timeout.pyc
     6289  03-08-2017 20:16   requests/packages/urllib3/util/url.py
     6914  03-08-2017 20:16   requests/packages/urllib3/util/url.pyc
     1451  03-08-2017 20:16   requests/packages/urllib3/util/wait.py
     2066  03-08-2017 20:16   requests/packages/urllib3/util/wait.pyc
    26216  03-08-2017 20:16   requests/sessions.py
    22473  03-08-2017 20:16   requests/sessions.pyc
     3316  03-08-2017 20:16   requests/status_codes.py
     4649  03-08-2017 20:16   requests/status_codes.pyc
     3012  03-08-2017 20:16   requests/structures.py
     6141  03-08-2017 20:16   requests/structures.pyc
    24827  03-08-2017 20:16   requests/utils.py
    24866  03-08-2017 20:16   requests/utils.pyc
        0  03-08-2017 20:16   requests-2.13.0.dist-info/
    43228  03-08-2017 20:16   requests-2.13.0.dist-info/DESCRIPTION.rst
        4  03-08-2017 20:16   requests-2.13.0.dist-info/INSTALLER
    44453  03-08-2017 20:16   requests-2.13.0.dist-info/METADATA
     1360  03-08-2017 20:16   requests-2.13.0.dist-info/metadata.json
    13560  03-08-2017 20:16   requests-2.13.0.dist-info/RECORD
        9  03-08-2017 20:16   requests-2.13.0.dist-info/top_level.txt
      110  03-08-2017 20:16   requests-2.13.0.dist-info/WHEEL
        0  03-08-2017 20:16   src/
      185  03-08-2017 20:16   src/pip-delete-this-directory.txt
        0  03-08-2017 20:16   src/python-firebase/
        0  03-08-2017 20:16   src/python-firebase/.git/
        0  03-08-2017 20:16   src/python-firebase/.git/branches/
      319  03-08-2017 20:16   src/python-firebase/.git/config
       73  03-08-2017 20:16   src/python-firebase/.git/description
       23  03-08-2017 20:16   src/python-firebase/.git/HEAD
        0  03-08-2017 20:16   src/python-firebase/.git/hooks/
      478  03-08-2017 20:16   src/python-firebase/.git/hooks/applypatch-msg.sample
      896  03-08-2017 20:16   src/python-firebase/.git/hooks/commit-msg.sample
      189  03-08-2017 20:16   src/python-firebase/.git/hooks/post-update.sample
      424  03-08-2017 20:16   src/python-firebase/.git/hooks/pre-applypatch.sample
     1642  03-08-2017 20:16   src/python-firebase/.git/hooks/pre-commit.sample
     1348  03-08-2017 20:16   src/python-firebase/.git/hooks/pre-push.sample
     4951  03-08-2017 20:16   src/python-firebase/.git/hooks/pre-rebase.sample
      544  03-08-2017 20:16   src/python-firebase/.git/hooks/pre-receive.sample
     1239  03-08-2017 20:16   src/python-firebase/.git/hooks/prepare-commit-msg.sample
     3610  03-08-2017 20:16   src/python-firebase/.git/hooks/update.sample
      490  03-08-2017 20:16   src/python-firebase/.git/index
        0  03-08-2017 20:16   src/python-firebase/.git/info/
      240  03-08-2017 20:16   src/python-firebase/.git/info/exclude
        0  03-08-2017 20:16   src/python-firebase/.git/logs/
      198  03-08-2017 20:16   src/python-firebase/.git/logs/HEAD
        0  03-08-2017 20:16   src/python-firebase/.git/logs/refs/
        0  03-08-2017 20:16   src/python-firebase/.git/logs/refs/heads/
      198  03-08-2017 20:16   src/python-firebase/.git/logs/refs/heads/master
        0  03-08-2017 20:16   src/python-firebase/.git/logs/refs/remotes/
        0  03-08-2017 20:16   src/python-firebase/.git/logs/refs/remotes/origin/
      198  03-08-2017 20:16   src/python-firebase/.git/logs/refs/remotes/origin/HEAD
        0  03-08-2017 20:16   src/python-firebase/.git/objects/
        0  03-08-2017 20:16   src/python-firebase/.git/objects/info/
        0  03-08-2017 20:16   src/python-firebase/.git/objects/pack/
     2752  03-08-2017 20:16   src/python-firebase/.git/objects/pack/pack-e76e0e23b3d405b43031afd8eb87481de99b3eb5.idx
     9436  03-08-2017 20:16   src/python-firebase/.git/objects/pack/pack-e76e0e23b3d405b43031afd8eb87481de99b3eb5.pack
      252  03-08-2017 20:16   src/python-firebase/.git/packed-refs
        0  03-08-2017 20:16   src/python-firebase/.git/refs/
        0  03-08-2017 20:16   src/python-firebase/.git/refs/heads/
       41  03-08-2017 20:16   src/python-firebase/.git/refs/heads/master
        0  03-08-2017 20:16   src/python-firebase/.git/refs/remotes/
        0  03-08-2017 20:16   src/python-firebase/.git/refs/remotes/origin/
       32  03-08-2017 20:16   src/python-firebase/.git/refs/remotes/origin/HEAD
        0  03-08-2017 20:16   src/python-firebase/.git/refs/tags/
       39  03-08-2017 20:16   src/python-firebase/.gitignore
        0  03-08-2017 20:16   src/python-firebase/firebase/
     2504  03-08-2017 20:16   src/python-firebase/firebase/__init__.py
        0  03-08-2017 20:16   src/python-firebase/python_firebase.egg-info/
        1  03-08-2017 20:16   src/python-firebase/python_firebase.egg-info/dependency_links.txt
      376  03-08-2017 20:16   src/python-firebase/python_firebase.egg-info/PKG-INFO
       25  03-08-2017 20:16   src/python-firebase/python_firebase.egg-info/requires.txt
      214  03-08-2017 20:16   src/python-firebase/python_firebase.egg-info/SOURCES.txt
        9  03-08-2017 20:16   src/python-firebase/python_firebase.egg-info/top_level.txt
     1744  03-08-2017 20:16   src/python-firebase/README.md
       25  03-08-2017 20:16   src/python-firebase/requirements.txt
      510  03-08-2017 20:16   src/python-firebase/setup.py
---------                     -------
  3104275                     265 files

1 个答案:

答案 0 :(得分:2)

嗨,所以我终于解决了。事实证明它给了我这个错误,因为它无法导入Firebase依赖关系,因为Firebase位于名为src的文件夹中。