使用 AWS Lambda 抓取网站并将数据保存在 S3 上。
当我执行 Lambda 时,出现以下错误消息。
{“errorMessage”:“无法导入模块“lambda_function”:无法从“urllib3.util.ssl_”(/opt/python/urllib3/util/ssl_.py)导入名称“DEFAULT_CIPHERS””,“errorType”:“运行时.ImportModuleError", "requestId": "fb66bea9-cbad-4bd3-bd4d-6125454e21be", "stackTrace": [] }
最小 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
Run Code Online (Sandbox Code Playgroud)
Lambda 上添加了一层。使用以下命令将文件保存在python文件夹中,冻结在 zip 文件中,然后作为层上传到 AWS Lambda。
!pip install requests -t ./python --no-user
!pip install pandas -t ./python --no-user
!pip install beautifulsoup4 -t ./python --no-user
Run Code Online (Sandbox Code Playgroud)
horserace-dx已存在raw存在我搜索“无法从‘urllib3.util.ssl_’导入名称‘DEFAULT_CIPHERS’”并找到了一些建议。我用以下代码制作了图层,然后再次尝试,但没有成功。
!pip install …Run Code Online (Sandbox Code Playgroud)