简体   繁体   English

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

[英]Deploying a microservice with Tensorflow at AWS Lambda

I have been stuck here for too long.我被困在这里太久了。 I am trying to deploy a microservice that uses tensorflow.我正在尝试部署一个使用 tensorflow 的微服务。 There is a single file by the name of handler.py which has the simple code below:有一个名为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
    }
    """

To make my work easier I am using serverless to deploy a microservice but it fails saying, unzipped size is too big.为了让我的工作更轻松,我使用无服务器来部署微服务,但它没有说,解压缩的大小太大。 Here is how my directory looks like:这是我的目录的样子:

-- handler.py
-- serverless.yml
-- requirements.txt

requirements.txt looks like: requirements.txt看起来像:

numpy
tensorflow

I also tried to upload without installing the above modules thinking that lambda will itself initialize from requirements.txt but then get an error that Unable to import module 'handler': No module named 'tensorflow' .我还尝试在不安装上述模块的情况下上传,认为 lambda 本身会从requirements.txt初始化,但随后收到错误消息Unable to import module 'handler': No module named 'tensorflow' What should I do?我该怎么办? I have spent lots of time in this and still not convinced that AWS Lambda would not allow me to do this.我在这方面花了很多时间,但仍然不相信 AWS Lambda 不允许我这样做。

If you wanted to see serverless.yml , it looks as follows:如果您想查看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 

As you've mentioned from the error you received it looks like your zipped package is too large.正如您在收到的错误中提到的那样,您的压缩包看起来太大了。 You received that other error because you have a module requirement in your script to use tensorflow.您收到了另一个错误,因为您的脚本中有一个模块要求使用 tensorflow。

Keep in mind the AWS Lambda Limits has a 50MB deployment package size limit.请记住, AWS Lambda 限制有 50MB 的部署包大小限制。 The Tensorflow package by itself is close to 50MB, so adding the Numpy package will take it well over the limit. Tensorflow 包本身接近 50MB,因此添加 Numpy 包将远远超过限制。

Have a look at this blog which does some investigation into the package limit sizing in AWS Lambda看看这个博客,它对 AWS Lambda 中的包限制大小进行了一些调查

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

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

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