【发布时间】:2020-01-15 23:26:17
【问题描述】:
我被困在这里太久了。我正在尝试部署一个使用 tensorflow 的微服务。有一个名为handler.py 的文件,其简单代码如下:
import json
import tensorflow as tf
import numpy as np
def main(event, context):
# a = np.arange(15).reshape(3, 5)
body = {
"message": "Go Serverless v1.0! Your function executed successfully!",
"input": event
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response
# Use this code if you don't use the http event with the LAMBDA-PROXY
# integration
"""
return {
"message": "Go Serverless v1.0! Your function executed successfully!",
"event": event
}
"""
为了让我的工作更轻松,我使用了serverless to deploy a microservice,但它没有说,解压缩后的大小太大。这是我的目录的样子:
-- handler.py
-- serverless.yml
-- requirements.txt
requirements.txt 看起来像:
numpy
tensorflow
我还尝试在不安装上述模块的情况下上传,认为 lambda 本身会从 requirements.txt 初始化,但随后会收到 Unable to import module 'handler': No module named 'tensorflow' 的错误。我应该怎么办?我在这方面花了很多时间,但仍然不相信 AWS Lambda 不允许我这样做。
如果你想看serverless.yml,它看起来如下:
service: numpy-new-test
provider:
name: aws
runtime: python3.6
profile: nsp
role: arn:aws:iam::xxxxxxxxxxx7:role/AdminRole
functions:
numpy:
handler: handler.main
events:
- http:
path: test
method: get
【问题讨论】:
标签: python amazon-web-services tensorflow aws-lambda