[英]How to avoid packaging requests every time I need to use it in a Lambda?
This is in reference to the change to removal of the vendored version of requests from botocore as seen here: https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/这是参考从 botocore 删除供应商版本请求的更改,如下所示: https ://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore /
I've been changing existing lambdas for this change.我一直在为此更改更改现有的 lambda。 For simple get requests I've just been using urllib3 since it is part of std lib but have ran into issues attempting to use it for more complex calls such as setting many headers, authing and posting content.对于简单的获取请求,我一直在使用 urllib3,因为它是 std lib 的一部分,但在尝试将其用于更复杂的调用(例如设置许多标头、身份验证和发布内容)时遇到了问题。 I've found various posts, including on SO, that recommend just using requests, which I must say I do prefer.我发现了各种帖子,包括在 SO 上,建议只使用请求,我必须说我更喜欢。
That said, the only way I know of to do that successfully in lambda going forward is by performing "pip install requests -t ./" and then zipping up a deployment package(documentation here: https://aws.amazon.com/premiumsupport/knowledge-center/build-python-lambda-deployment-package/ ) for each and every one of my lambdas that requires the use of requests.也就是说,我知道在 lambda 中成功执行此操作的唯一方法是执行“pip install requests -t ./”,然后压缩部署包(此处的文档: https : //aws.amazon.com/ premiumsupport/knowledge-center/build-python-lambda-deployment-package/ )适用于我的每一个需要使用请求的 lambda。
Am I being daft here?我在这里傻吗? Is there an easier or better way to do this or is it my only option?有没有更简单或更好的方法来做到这一点,还是我唯一的选择? How wasteful would it be to have a lambda function behind an api gateway that imported requests and all of my other lambdas called(using urllib3) and passed parameters that made the call and replied back?在 api 网关后面有一个 lambda 函数来导入请求和我所有的其他 lambdas 调用(使用 urllib3)并传递进行调用并回复的参数会有多浪费?
I feel like I must be overlooking a better way of doing this, please enlighten me!我觉得我必须忽略一个更好的方法,请赐教!
将requests
放入 Lambda 层并在您的各种 Lamdba 函数中使用该层
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.