繁体   English   中英

aws-sam-cli Python requirements.txt 在自定义模板时从部署的 Lambda 中丢失。yaml

[英]aws-sam-cli Python requirements.txt missing from deployed Lambda when custom template.yaml

我有几个用于同一个项目的 AWS SAM 模板,其中 lambdas 使用 Python 3.8,部分用于不同的环境,部分用于尝试新事物,我使用-t my-template.yaml来指定要使用的模板。

我使用常规sam build -t my-template.yaml && sam deploy -t my-template.yaml

问题:requirements.txt 文件似乎在构建步骤中受到尊重,部署步骤似乎被忽略了。

.aws-sam/build/MyFunction包含要求:$ ls app.py certifi-2020.12.5.dist-info chardet-4.0.0.dist-info idna-2.10.dist-info pymysql rds_config.py requests-2.25。 1.dist-info urllib3 certifi chardet idna init .py PyMySQL-1.0.2.dist-info requests requirements.txt urllib3-1.26.3.dist-info

但是在云中运行时,lambda 失败,并出现异常说找不到 pymysql,当我在 AWS UI 中检查 function 时,没有包含任何要求(例如,没有 PyMySQL-1.0.2.dist-info) .

我注意到,如果我不在sam deploy上使用-t标志,而只在其中有默认的template.yaml文件,那么似乎包含正确的要求,并且 lambda 运行成功。

我可能做错了什么?

requirements.txt 内容:

$ cat requirements.txt
requests
pymysql

山姆版本:

$ sam --version
SAM CLI, version 1.18.1

操作系统:

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
....

解决方案是使用:

sam build -t my-template.yaml

但是然后做:

sam deploy

无需再次添加-t my-template.yaml

从下面的票中回答:

您正在做的是告诉sam deploy使用指向非构建函数的“源模板”。 相反,如果您从sam deploy命令中删除-t ,SAM CLI 将从.aws-sam/build/template.yaml中获取构建的模板,该模板将“安装”所有依赖项。

https://github.com/aws/serverless-application-model/issues/1927

暂无
暂无

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

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