繁体   English   中英

在 AWS Lambda 上使用 Tensorflow 部署微服务

[英]Deploying a microservice with Tensorflow at AWS Lambda

我被困在这里太久了。 我正在尝试部署一个使用 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
    }
    """

为了让我的工作更轻松,我使用无服务器来部署微服务,但它没有说,解压缩的大小太大。 这是我的目录的样子:

-- 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 

正如您在收到的错误中提到的那样,您的压缩包看起来太大了。 您收到了另一个错误,因为您的脚本中有一个模块要求使用 tensorflow。

请记住, AWS Lambda 限制有 50MB 的部署包大小限制。 Tensorflow 包本身接近 50MB,因此添加 Numpy 包将远远超过限制。

看看这个博客,它对 AWS Lambda 中的包限制大小进行了一些调查

https://hackernoon.com/exploring-the-aws-lambda-deployment-limits-9a8384b0bec3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM