Cannot use Requests-Module on AWS Lambda

后端 未结 5 1465
故里飘歌
故里飘歌 2020-12-02 11:56

I need to do a rest-call within a python script, that runs once per day. I can\'t pack the \"requests\" package into my python-package using the AWS Lambdas. I get the error

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 12:43

    I believe you have lambda_function.py on the Lambda console. You need to first create the Lambda function deployment package, and then use the console to upload the package.

    • You create a directory, for example project-dir on your system (locally)
    • create lambda_function.py in project-dir, copy the content of lambda_function.py from lambda console and paste it in project-dir/lambda_function.py
    • pip install requests -t /path/to/project-dir
    • Zip the content of the project-dir directory, which is your deployment package (Zip the directory content, not the directory)

    Go to the Lambda console, select upload zip file in code entry type and upload your deployment package. Import requests should work without any error.

提交回复
热议问题