Python at AWS Lambda: `requests` from botocore.vendored deprecated, but `requests` not available

后端 未结 7 2328
梦如初夏
梦如初夏 2021-02-07 16:07

I\'ve got a Python script for an AWS Lambda function that does HTTP POST requests to another endpoint. Since Python\'s urllib2.request, https://docs.python.org/2/li

7条回答
  •  生来不讨喜
    2021-02-07 16:42

    Check out the instructions here: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-dependencies

    All you need to do is download the requests module locally, then include it in your Lambda function deployment package (ZIP archive).

    Example (if all your Lambda function consisted of was a single Python module + requests module):

    $ pip install --target ./package requests
    $ cd package
    $ zip -r9 ${OLDPWD}/function.zip .
    $ cd $OLDPWD
    $ zip -g function.zip lambda_function.py
    $ aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
    

提交回复
热议问题