How to have automatic loading of changes with "sam local start-api" using libraries, without first running "sam build"?

14 views Asked by At

I have bootstrapped an SAM application as follows:

sam init --app-template hello-world-powertools-python --name sam-app --package-type Zip --runtime python3.12 --no-tracing

I have created a virtual environment in the hello_worldfunction directory for my function dependencies:

(venv) $ la hello_world/
total 16
-rw-r--r--  1 xxx  staff     0B Mar 28 14:51 __init__.py
-rw-r--r--  1 xxx  staff   1.2K Mar 28 15:56 app.py
-rw-r--r--@ 1 xxx  staff    47B Mar 28 15:28 requirements.txt
drwxr-xr-x  6 xxx  staff   192B Mar 28 15:07 venv

Everything works, when running sam build && sam local start-api, but with no automatic reloading of changes:

https://github.com/aws/aws-sam-cli/issues/901#issuecomment-657193066

If I delete .aws_samand run sam local start-api, then changes are automatically loaded, but then I get errors that e.g. requestscan't be imported, as the libraries are not available:

Invalid lambda response received: Invalid API Gateway Response Keys: {'errorType', 'stackTrace', 'errorMessage', 'requestId'} in {'errorMessage': "Unable to import 
module 'app': No module named 'requests'", 'errorType': 'Runtime.ImportModuleError', 'requestId': 'c2921e8a-34bc-43b4-9c74-b6b434f5c346', 'stackTrace': []} 

How can I make the libraries available?

Note: sam-buildmakes the dependencies available by copying them into a single directory together with app.py (entrypoint), but I don't want dependencies alongside source code

0

There are 0 answers