Skip to content

Instantly share code, notes, and snippets.

@AMMullan
Last active July 22, 2022 13:07
Show Gist options
  • Save AMMullan/1b65f1c1111c9d41b97af9a854f971b5 to your computer and use it in GitHub Desktop.
Save AMMullan/1b65f1c1111c9d41b97af9a854f971b5 to your computer and use it in GitHub Desktop.
Create Lambda Layer for Python (Multiple Runtimes)
#!/bin/bash
# Expects a requirements.txt in the same folder
# Note: if the package includes NumPy and SciPy, consider defining the package
# and the dependencies that aren't these as they're natively available in Layers
# Supported Docker Images are available here:
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-image-repositories.html
layer_versions="python3.8 python3.9"
export PKG_DIR="python"
rm -rf ${PKG_DIR} && mkdir -p ${PKG_DIR}
for version in ${layer_versions[@]}; do
image="public.ecr.aws/sam/build-${version}"
docker run -v "$PWD":/var/task $image /bin/sh -c "pip install -r requirements.txt -t python/lib/${version}/site-packages/; exit"
done
zip -qr layer.zip python
sudo rm -rf ${PKG_DIR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment