For starters, I have tried the following posts & they did not help.
Using Django ORM Inside AWL Lambda
Using Only The Db Part Of Django
Following the django docs and using pieces of the above links I created the following standalone script to use django's ORM.
import django
from django.conf import settings
def configure():
settings.configure(DEBUG=False,
DATABASES={
# TODO: Change this to environment variables
'default': {
"ENGINE": "django.db.backends.mysql",
"NAME": "db_name",
"HOST": "db_host",
"USER": "admin",
"PASSWORD": "db_pass"
}
},
INSTALLED_APPS=['my_models']
)
django.setup()
In my handler.py file with my registerUser lambda functions
from .django_orm.main import configure
configure()
from .django_orm.my_models import AppUser
def registerUser(event, context):
#Application Logic
newUser = AppUser()
newUser.save()
return True
When I run this I get the following error ...
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'my_models'
My directory structure is the following:
./myServerlessProject
./djangoORM
./main.py
./manage.py
./my_models
./__init__.py
./models.py
./handler.py
./serverless.yml
What am I doing wrong and how do I get the django ORM to be stand-alone?