简体   繁体   English

AWS Lambda - 上传的依赖项不加载依赖项的依赖项

[英]AWS Lambda - Uploaded dependency doesn't load the dependency's dependency

I've looked around but have had a hard time finding someone with a similar problem.我环顾四周,但很难找到有类似问题的人。 Most of the articles I come across have a hard time deploying a package. My problem is that the package I uploaded has a hard time finding its resources.我遇到的大多数文章都很难部署 package。我的问题是我上传的 package 很难找到它的资源。

For more context: I am using python3, I have used both RedHat 7 and Windows 10 to follow these instructions to create the layer I need, and I have successfully been able to follow them to create a layer and import it into my lambda_function.py file.有关更多上下文:我正在使用 python3,我使用了 RedHat 7 和 Windows 10 来按照这些说明创建我需要的层,并且我已经成功地能够按照它们创建层并将其导入我的 lambda_function.py文件。 The module I am trying to import is called qrcode .我要导入的模块称为qrcode When the virtual environment is activated, I installed it with pip install qrcode[pil] on Windows 10 and pip3 install qrcode[pil] on my RedHat 7 ec2 instance.激活虚拟环境后,我使用pip install qrcode[pil] on Windows 10 和pip3 install qrcode[pil]在我的 RedHat 7 ec2 实例上安装它。 I have also tried to include a separate layer for pil itself, to which it still didn't work.我还尝试为 pil 本身包含一个单独的层,但它仍然不起作用。

The error: The stacktrace is as follows -错误:堆栈跟踪如下 -

{
  "errorMessage": "No module named 'Image'",
  "errorType": "ModuleNotFoundError",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 30, in lambda_handler\n    img = qrcode.make(data)\n",
    "  File \"/opt/python/qrcode/main.py\", line 13, in make\n    return qr.make_image()\n",
    "  File \"/opt/python/qrcode/main.py\", line 296, in make_image\n    from qrcode.image.pil import PilImage\n",
    "  File \"/opt/python/qrcode/image/pil.py\", line 7, in <module>\n    import Image\n"
  ]
}

I got it to work, though I'm not 100% pleased with the answer.我让它工作了,尽管我对答案不是 100% 满意。

Long story short, qrcode had an issue importing PIL.长话短说, qrcode在导入 PIL 时遇到问题。 I came across this answer that talked about how lambda is missing some components in how it was built.我遇到了这个答案,它谈到了 lambda 如何在构建过程中缺少一些组件。 So I installed my package ( pip install qrcode ) and imported it as a layer, then I used an arn specific for pil (talked about here ), and it worked like a charm.所以我安装了我的 package ( pip install qrcode ) 并将其导入为一个层,然后我使用了一个特定于 pil 的 arn (在这里讨论过),它的工作就像一个魅力。

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

相关问题 如何在AWS Lambda C#实现中使用依赖注入 - How to use Dependency Injection in AWS Lambda C# implementation 我可以通过 python 在 aws lambda 中运行 Maven 依赖项吗? - Can i run maven dependency in aws lambda via python? 作为依赖项的存储库不会影响更改 - Repository as dependency doesn't affect changes AWS Glue - AWSGlueETL 依赖关系未解决 - AWS Glue - AWSGlueETL dependency not resolved .NET Core 3.1 - 组件的依赖解析失败 - AWS Mock Lambda 测试工具 - .NET Core 3.1 - Dependency resolution failed for component - AWS Mock Lambda Test Tools AWS CDK Init 容器依赖与 Fargate 模式 - AWS CDK Init Container dependency with Fargate Pattern 如果 webhook URL 在 S3 通知 lambda 中传递,CDK 会创建循环依赖 - CDK Creats cyclic dependency if webhook URL is passed in S3 notification lambda 如何从 AWS S3 运行具有 JAR 依赖项的 Apache Spark 应用程序? - How to run Apache Spark applications with a JAR dependency from AWS S3? 资源之间的循环依赖。 Cognito - lambda 触发器 - Circular dependency between resources. Cognito - lambda trigger 如何使用 Amazon AWS Elastic Beanstalk 部署私有 python pip 依赖项? - How to deploy private python pip dependency with Amazon AWS Elastic Beanstalk?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM