AWS Lambda import module error in python

后端 未结 21 1489
醉话见心
醉话见心 2020-12-07 19:56

I am creating a AWS Lambda python deployment package. I am using one external dependency requests . I installed the external dependency using the AWS documentation http://do

21条回答
  •  失恋的感觉
    2020-12-07 20:14

    A perspective from 2019:

    AWS Lambda now supports Python 3.7, which many people (including myself) choose to use as the runtime for inline lambdas.

    Then I had to import an external dependency and I followed AWS Docs as the OP referred to. (local install --> zip --> upload).

    I had the import module error and I realised my local PC had Python 2.7 as the default Python. When I invoked pip, it installed my dependency for Python 2.7.

    So I switched locally to the Python version that matches the selected runtime version in the lambda console and then re-installed the external dependencies. This solved the problem for me. E.g.:

    $ python3 -m pip install --target path/to/lambda_file 
    

提交回复
热议问题