简体   繁体   English

每次我需要在 Lambda 中使用它时如何避免打包请求?

[英]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.

相关问题 每次我调用 S3 static 站点时,我如何触发 lambda function - How i trigger a lambda function every time I call a S3 static site 我需要知道这条线在lambda function中的使用 - I need to know the use of this line in lambda function 如何在打包时为别名设置python模块? - How do I alias a python module at packaging time? 每次我想使用来自多个 python 版本的 python3 时都需要取消设置 PYTHONPATH - Need to unset PYTHONPATH every time when I want to use python3 from multiple python versions 如何避免每次调用 python 脚本时都重新加载 ML model? - How to avoid reloading ML model every time when I call python script? 每次更新都需要更改AWS Lambda部署软件包的分钟代码 - AWS Lambda Deployment Package minute code change need every time update 如何避免python中的yield命令每次都抛出异常? - How to avoid yield command in python throws exceptions every time? 如何避免每次加载机器学习 model? - How to avoid loading a machine learning model every time? 每次重新加载python模块时如何避免计算 - How to avoid computation every time a python module is reloaded 如何为所有 aws lambda 请求使用单个 pymongo 连接池 - How to use single pymongo connection pool for all aws lambda requests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM