Pillow, numpy, imagehash via macbook for AWS lambda

requirements.txt

requests==2.32.0
imagehash==4.3.2
  1. download numpy whl file of numpy from https://pypi.org/project/numpy/#files
  2. download scipy whl the same way
  3. scipy-1.15.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  4. build.sh
#!/bin/zsh
set -e
ZIP_NAME="lambda_package.zip"

LAMBDA_DIR="lambda_build"

rm -rf "$LAMBDA_DIR" "$ZIP_NAME"
mkdir "$LAMBDA_DIR"

cp lambda_function.py requirements.txt "$LAMBDA_DIR"

docker run --rm -v "$PWD/$LAMBDA_DIR":/var/task python:3.13 \
/bin/bash -c "
pip install -r /var/task/requirements.txt -t /var/task &&
pip install --platform manylinux2014_x86_64 --target=python/lib/python3.13/site-packages --implementation cp --python-version 3.13 --only-binary=:all: --upgrade numpy
rm /var/task/requirements.txt
"

cd "$LAMBDA_DIR"
rm -rf PIL
rm -rf pillow-11.2.1.dist-info
rm -rf pillow.libs
rm -rf numpy.libs
rm -rf numpy-2.2.6.dist-info
rm -rf numpy

unzip -o ../numpy-2.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -d .
unzip -o ../scipy-1.15.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -d .
zip -r9 "../$ZIP_NAME" .
cd ..

rm -rf "$LAMBDA_DIR"

2. find a layer via aws. it has a name: “Lambda Layer with Pillow image processing library”

3. link you function with the layer

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started