在 AWS Lambda 上为 python 3.8 导入请求

Vin*_*lvo 5 python python-requests aws-lambda python-3.8

requests从 botocore.vendored使用的技巧不再适用于 AWS Lambda 上的 Python 3.8,我认为它包括最新的 botocore-1.13。此版本不再嵌入requests. 导入它有效,但包实际上是空的。

[ERROR] AttributeError: module 'botocore.vendored.requests' has no attribute 'post'
Run Code Online (Sandbox Code Playgroud)

有没有办法requests在本机 lambda上导入?这是一个基本的过程,为非常简单的 Lambda 打包代码会很痛苦。

或者,任何人都有另一种技巧来调用 API-Gateway 而没有requests?

not*_*est -2

单独安装requests依赖项。

$ pip install requests

使用下面的导入。

import requests
response = requests.get('https://...')
Run Code Online (Sandbox Code Playgroud)

删除供应的版本和替代解决方案

引入此更改的相关 PR

  • 这在默认的 lambda 环境中是不可能的。 (2认同)