【发布时间】:2020-10-30 19:30:17
【问题描述】:
我正在关注this tutorial,以便使用 python 设置无服务器 AWS lambda。
我想用无服务器 lambda 运行这个简单的 httprequest 函数(位于 httprequest.py 中):
import requests
def handler(event, context):
r = requests.get("https://news.ycombinator.com/news")
return {"content": r.text}
以下是我的 serverless.yaml:
service: serverlessProj
frameworkVersion: '2'
provider:
name: aws
runtime: python3.8
functions:
hello:
handler: hello.handler
httprequest:
handler: httprequest.handler
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: true
现在,如您所见,自定义部分告诉 serverless-python-requirements 插件在 Docker 容器中编译 Python 包。它应该安装 requirements.txt 中的插件。这是requirements.txt的内容:
requests
运行sls deploy时,这是控制台输出:
Serverless: Generated requirements from /Users/user/Desktop/ShoeSwiper/Serverless/requirements.txt in /Users/user/Desktop/ShoeSwiper/Serverless/.serverless/requirements.txt...
Serverless: Installing requirements from /Users/user/Library/Caches/serverless-python-requirements/007/requirements.txt ...
Serverless: Docker Image: lambci/lambda:build-python3.8
Serverless: Using download cache directory /Users/user/Library/Caches/serverless-python-requirements/downloadCacheslspyc
Serverless: Running docker run --rm -v /Users/user/Library/Caches/serverless-python-requirements/007\:/var/task\:z -v /Users/user/Library/Caches/serverless-python-requirements/downloadCacheslspyc\:/var/useDownloadCache\:z -u 0 lambci/lambda\:build-python3.8 python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache...
然后它就卡住了。知道有什么问题。我错过了什么吗?
【问题讨论】:
标签: python docker serverless