How I customize the sam build to pass a ssh and access my private repo on GitHub?
Asked Answered
G

1

8

I created a stack of lambda functions and I use the ide pycharm to test them on my localhost. In the requirements.txt file I added a reference to a private repository on github.

The repository works and I was able to install it through the requirements.txt of other projects.

But when I start the local test, using aws sam cli, sam buil fails, because the container does not have the ssh key to access the repository.

Is there any way to customize the sam build process and give it my ssh key to the container access my private repo and install the package?

Or any another solution?

Gerfen answered 16/6, 2020 at 2:41 Comment(0)
M
5

This solution is written for Python, but it's probably applicable one way or another to node.js, Java etc.

I'm using the following workaround. At first it seems to defeat the purpose of building in a container, but if your private repositories are not compiled natively you should be fine. Direct dependencies that are compiled natively will be properly installed in the context of the container.

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/

If your private dependencies depend on libraries that are compiled natively, you can either add them to the temporary public_requirements.txt, or install them in another container and then copy to build/LambdaFunction/.

Menology answered 31/8, 2020 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.