Skip to content

Instantly share code, notes, and snippets.

@qtangs
Last active August 21, 2021 02:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save qtangs/69e0db74313e8b97708b88f9a7db9bfb to your computer and use it in GitHub Desktop.
Save qtangs/69e0db74313e8b97708b88f9a7db9bfb to your computer and use it in GitHub Desktop.
Get packages for AWS Lambda Layer
#!/bin/bash
export PKG_DIR="python"
rm -rf ${PKG_DIR} && mkdir -p ${PKG_DIR}
docker run --rm -v $(pwd):/foo -w /foo lambci/lambda:build-python3.6 \
pip install -r requirements.txt --no-deps -t ${PKG_DIR}
@fricative
Copy link

I was following your article https://medium.com/@qtangs/creating-new-aws-lambda-layer-for-python-pandas-library-348b126e9f3e. very interesting and useful post. But when I execute this shell script, I get the following error message

Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'

and my folder structure is the same as yours in your post. Wonder if you could shed some light. thanks.

@openrory
Copy link

openrory commented Mar 6, 2019

the requirements.txt should be in the current directory. If you don't run the bash or Docker command in the same directory, switch to that directory or change the path to /requirements.txt

@mybluedog24
Copy link

mybluedog24 commented Mar 6, 2019

I still got the error even the file is in the current directory. I also tried the absolute path but still the same error.
I fixed it by copying the code directly from this gist and it just works without any errors.

@sobolevnrm
Copy link

This is a very helpful gist. Note that if you're running the commands outside of bash via Powershell on Windows, you'll need to add quotes around the -v portion of the argument: -v "$(pwd):/foo".

@Gaploid
Copy link

Gaploid commented May 12, 2020

if you receive error: docker: invalid reference format: repository name must be lowercase.
Then add quotes around $pwd if you have spaces in your patch to working directory. It should look like that.

docker run --rm -v "$(pwd)":/foo -w /foo lambci/lambda:build-python3.6 \
    pip install -r requirements.txt --no-deps -t ${PKG_DIR}

@mrufsvold
Copy link

Thank you so much for this script!

I've tried quotes and no quotes around $(pwd). I also tried writing the file path to my current working directory in to the script and adding a cd to the correct directory at the beginning.

However, I keep getting the same result --
docker: Error response from daemon: the working directory 'C:/Program Files/Git/foo' is invalid, it needs to be an absolute path.

I'm running the script from inside Git Bash on Windows 10. Any thoughts on what I'm doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment