Skip to content

Instantly share code, notes, and snippets.

@ttor
Last active March 25, 2022 17:47
Show Gist options
  • Save ttor/8a1da161f2cfed589d9a528cbf2acb94 to your computer and use it in GitHub Desktop.
Save ttor/8a1da161f2cfed589d9a528cbf2acb94 to your computer and use it in GitHub Desktop.
Create AWS Lambda Layer for Matplotlib (Python3.7)
sudo docker pull amazonlinux
sudo docker run -it amazonlinux:latest /bin/bash
# inside container
yum -y install python37 zip
python3 -m venv python
source python/bin/activate
pip3 install matplotlib
deactivate
rm -rf python/{bin,include,lib64,pyvenv.cfg} python/lib/python3.7/site-packages/{__pycache__,easy_install.py,numpy*,pip*,pkg_resources,setuptools*}
zip -r aws_lambda_python37_layer_matplotlib.zip python/
# in other terminal, copy file from container to host
CONTAINER_ID=$(sudo docker ps|grep amazonlinux|cut -d " " -f1)
sudo docker cp ${CONTAINER_ID}:/aws_lambda_python37_layer_matplotlib.zip .
# exit container
exit
@salimhb
Copy link

salimhb commented Jan 25, 2022

Thanks, this helped me a lot. In case someone else is trying to run this on Apple Silicon, make sure to set the --platform parameter so that pip3 install installs the binaries for the correct architecture:

docker run --platform linux/amd64 -it amazonlinux:latest /bin/bash

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