I've enjoyed learning about the <opinionated monor...
# sst
s
I've enjoyed learning about the opinionated monorepo example for Typescript apps. Is there an analogous example for python floating around?
t
Unfortunately I know next to nothing about python
s
Yeah, me too 🙂
I'm experimenting with various setups using the SST Rest API Python example. It works fine locally when using
sst start
, but has a runtime error after I
sst deploy
.
Copy code
[ERROR] Runtime.ImportModuleError: Unable to import module 'list': 

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.

We have compiled some common reasons and troubleshooting tips at:

    <https://numpy.org/devdocs/user/troubleshooting-importerror.html>

Please note and check the following:

  * The Python version is: Python3.8 from "/var/lang/bin/python3.8"
  * The NumPy version is: "1.21.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

Traceback (most recent call last):
this sort of problem (sst start works fine, sst deploy does not) is what I'm facing with the larger python project I'm working with. I wonder if there's a way to eliminate the discrepancy between running locally vs deployed to avoid this sort of issue.
t
yeah we just closed that gap more on the JS side, we probably need to do this for python as well
The difference between local + prod is very big
s
raised an issue to capture this particular error, but the larger conversation about closing the gaps between local and prod is probably more useful 🙂
wow, also, using a lambda layer to import Numpy reduced my Lambda package from 16.6MB to 3.1kb 😮
h
If you're using anything to do with Numpy I strongly suggest bundling it as a layer and importing it into your stack this is my go to repository for layers (https://github.com/keithrozario/Klayers) alternatively you can build it yourself. Layers saves you a TONNE of space and with the lambda size limit it also means you dont bundle each function with its own numpy. I've had the C-extensions issue before, either your python runtime is incompatible with the numpy you are using OR if you are using something like SciPy you might simply be missing the numpy package in that case you should supply both layers to the stack. I've got no issues since releasing to prod (all my lambda is in python).
s
Just found out about that layers repo today! I'll have to go through my lambdas to see which dependencies can move to layers. I don't use numpy myself, but I came across the error while using the SST python example. Super useful way to learn more about layers 🙂
ooh, I see
aws-psycopg2
, which is useful to me