[英]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.