【问题标题】:Adding a package to AWS Lambda将包添加到 AWS Lambda
【发布时间】:2020-04-15 23:51:17
【问题描述】:

我是 AWS Lambda 的新手,我正在尝试将 googles google-api-python-client 添加到我的函数中,到目前为止我所读到的就是这样做的方法:

  1. 我在本地下载文件 pip install google-api-python-client -t ./google,然后压缩 google 文件夹,将其作为 .zip 文件在 AWS lambda Create layer 部分中的一个层上传。
  2. 我对另一个包做同样的事情pip install google-auth-oauthlib -t ./google_auth
  3. 我的 lambda 函数如下所示:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

def lambda_handler(event, context):
    return ('test')

当我运行它时,我得到:

Response:
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'apiclient'",
  "errorType": "Runtime.ImportModuleError"
}

如何将这些包包含在我的脚本中?

【问题讨论】:

    标签: python amazon-web-services aws-lambda


    【解决方案1】:

    在使用层时,zip 文件应将所有模块/库包含在“python”文件夹中,如这里的 doc。您可以使用$ pip install google-api-python-client -t ./python 后跟zip -r layer.zip python 安装包,然后尝试将其作为新层上传并在函数中引用。

    您可以使用 $ zipinfo layer.zip$ unzip -l layer.zip 快速验证 .zip 文件的输出,以确保它符合文档中的要求 -

    pillow.zip
    │ python/PIL
    └ python/Pillow-5.3.0.dist-info
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      • 2023-02-08
      • 2020-02-25
      • 2020-11-10
      • 1970-01-01
      • 2018-10-29
      • 1970-01-01
      相关资源
      最近更新 更多