DEV Community

Sam
Sam

Posted on

Packaging and deploying Zappa applications on M1 silicon

When deploying Zappa applications, it's possible to package a version during deployment that can manifest is a bunch of missing dependency errors:

[ERROR] ImportError: Unable to import required dependencies: numpy: Error importing numpy: you should not try to import numpy from its source directory; please exit the numpy source tree, and relaunch your python interpreter from there. [ERROR] ImportError: Unable to import required dependencies: numpy: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. [ERROR] ImportError: No module named 'sklearn.__check_build._check_build' It seems that scikit-learn has not been built correctly. 
Enter fullscreen mode Exit fullscreen mode

Zappa claims to:

replace any dependencies with versions with wheels compatible with lambda

...but this doesn't seem to be the case (at least when building on apple M1 silicon). A fix I've found is to package and deploy within a docker container, which seems to work:

# Shell into a container. docker run --platform linux/amd64 -v $(pwd):/builds/ -it python:3.9.18-slim-bullseye /bin/bash # Create a virtual env to install dependencies. cd /builds/ python3 -m venv .venv && source .venv/bin/activate # Install the dependencies and zappa. pip install -r requirements.txt pip install zappa # Add credentials and deploy. mkdir ~/.aws && echo "creds" > ~/.aws/credentials zappa deploy dev 
Enter fullscreen mode Exit fullscreen mode

Ensure that the environment within the container matches that of your lambda deployment:

Deployed Zappa lambda

  • Confirm the 'Architecture' is the same by running arch within the container and comparing to the above.
  • Ensure the python version matches by running python --version and selecting the correct docker container from this list: https://hub.docker.com/_/python/tags

Top comments (0)