简体   繁体   English

无服务器 AWS Lambda 层与 python 包不工作。 奇怪的 hash 添加到 package 名称

[英]Serverless AWS Lambda Layer with python packages not working. Weird hash added to package name

When I manually create a Lambda Layer I add all the code inside the "python" folder as required, zip that folder, upload it and everything works.当我手动创建一个 Lambda 层时,我根据需要将所有代码添加到“python”文件夹中,zip 该文件夹,上传它,一切正常。

However, when I used Serverless (SLS), it correctly packages everything inside a "python.zip", but when I deploy the package folder is suddenly called "python-[HASH]".但是,当我使用无服务器 (SLS) 时,它正确地将所有内容打包在“python.zip”中,但是当我部署 package 文件夹时,它突然被称为“python-[HASH]”。 As a result, I cannot import the python dependencies from that layer.因此,我无法从该层导入 python 依赖项。

Why is there this hash?为什么会有这个hash? Is there a better way to deal with custom packages that are shared across Lambda functions?有没有更好的方法来处理跨 Lambda 函数共享的自定义包?

So it depends on how you package your function, below is my SAM template for function and the corresponding lambda layer:所以就看你怎么package你function了,下面是我的function和对应的lambda层的SAM模板:

    HelloWorldFunction:
        Type: AWS::Serverless::Functionn
        Properties:
        CodeUri: hello_world/
        Handler: app.lambda_handler
        Runtime: python3.8
        Role: !GetAtt LambdaRole.Arn
        Layers:
            - !Ref MyLambdaLayer

    MyLambdaLayer:
            Type: AWS::Serverless::LayerVersion
            Properties:
                LayerName: MyLambdaLayer
                ContentUri: lambda-layer/
                CompatibleRuntimes:
                - python3.8
                RetentionPolicy: Retain

And my directory structure for the packaging is:我的包装目录结构是:

.
├── README.md
├── hello_world
│   ├── app.py
│   └── requirements.txt
├── lambda-layer
│   └── python
│       └── lib
│           └── python3.8
│               └── site-packages
│                   └── hello.py
├── samconfig.toml
└── template.yaml

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

相关问题 使用无服务器框架将 Python package 部署到 AWS lambda 时出错 - Error deploying Python package to AWS lambda using Serverless framework 如何将 package AWS CDK 转化为 Lambda 层? - How to package AWS CDK into Lambda layer? 如何使用 AWS 的无服务器框架获取最新的 Layer 版本 Lambda - How to get latest Layer version with serverless framework for AWS Lambda 如何使用无服务器工具在 AWS lambda 上安装 librdKafka package - How to install librdKafka package on AWS lambda using serverless tool aws lambda 的重试机制不起作用。 超时异常后不重试 - Retry mechanism of aws lambda is not working. It is not retrying after timeout exception html-pdf package 不适用于 aws lambda - html-pdf package is not working on aws lambda 通过无服务器框架部署到 AWS Lambda 时,将 Package 文件放入应用程序包的特定文件夹 - Package files into specific folder of application bundle when deploying to AWS Lambda via Serverless Framework 无服务器 AWS Lambda CORS 错误 - Serverless AWS Lambda CORS Error 使用 AWS 保护无服务器后端 Lambda - Secure a serverless backend with AWS Lambda 如何访问上传到python aws lambda中的层的yaml文件 - How to access a yaml file uploaded to a layer in a python aws lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM