What I want to achieve
使用AWS Lambda抓取网站并将数据保存到S3.
The issues I'm having
当我执行Lambda时,出现以下错误消息.
{"errorMessage":"无法导入模块‘lambda_unction’:无法 从‘urllib3.util.ssl_’导入名称‘Default_ciphers’ (/opt/python/urllib3/util/ssl_.py)","errorType": "Runtime.ImportModuleError","questID": "fb66bea9-cad-4bd3-bd4d-6125454e21be","stacktrace":[]}
Code
最小Lambda代码如下所示.
import requests
import boto3
def lambda_handler(event, context):
s3 = boto3.client('s3')
upload_res = s3.put_object(Bucket='horserace-dx', Key='/raw/a.html', Body='testtext')
return event
向Lambda添加了一个层.使用以下命令将文件保存在python
文件夹中,并将其冻结为压缩文件,然后将其作为一个层上传到AWS Lambda.
!pip install requests -t ./python --no-user
!pip install pandas -t ./python --no-user
!pip install beautifulsoup4 -t ./python --no-user
- 桶
horserace-dx
存在 - 文件夹
raw
存在 - Lambda的角色设置得很好.它可以对S3进行读写
- Lambda的运行时是Python3.9.本地计算机的python版本为3.9.13.
What I did so far
我谷歌"无法从‘urllib3.util.ssl_’导入名称‘Default_ciphers’",并找到了一些建议.我用下面的代码制作了这一层,并再次try ,但没有成功.
!pip install requests -t ./python --no-user
!pip install pandas -t ./python --no-user
!pip install beautifulsoup4 -t ./python --no-user
!pip install urllib3==1.26.15 -t ./python --no-user
那么,我应该做些什么来实现我想要实现的目标呢?如有任何建议,我们将不胜感激.