7

我创建了一堆 lambda 函数,并使用 ide pycharm 在我的本地主机上测试它们。在 requirements.txt 文件中,我添加了对 github 上私有存储库的引用。

该存储库有效,我能够通过其他项目的 requirements.txt 安装它。

但是当我开始本地测试时,使用 aws sam cli,sam buil 失败,因为容器没有 ssh 密钥来访问存储库。

有没有办法自定义 sam 构建过程并将我的 ssh 密钥提供给容器访问我的私人仓库并安装包?

或者任何其他解决方案?

4

1 回答 1

5

该解决方案是为 Python 编写的,但它可能以一种或另一种方式适用于 node.js、Java 等。

我正在使用以下解决方法。起初它似乎违背了在容器中构建的目的,但如果你的私有存储库不是本地编译的,你应该没问题。本地编译的直接依赖项将正确安装在容器的上下文中。

grep -v "git+" requirements.txt > public_requirements.txt 
sam build --template-file "$TEMPLATE_FILE" --build-dir build --use-container --manifest public_requirements.txt

echo "Adding private dependencies"
grep "git+" requirements.txt | xargs python -m pip install --no-deps -t build/LambdaFunction/

如果您的私有依赖项依赖于本机编译的库,您可以将它们添加到临时库中public_requirements.txt,或者将它们安装在另一个容器中,然后复制到build/LambdaFunction/.

于 2020-08-31T10:13:50.360 回答