Hello,
for my purpose i founded a way to archived this:
first you need to connect throught SSH with eb ssh.
Then set your crontab to the "webapp" user :
sudo crontab -u webapp -e
On your crontab you can put your cron i.e.
* 2 * * * /var/app/venv/staging-LQM1lest/bin/python3 /var/app/current/manage.py test >> /var/log/app-logs/log-crontab.log 2>&1
(option) Finally, if you have a different settings.py file for production for instance settings_prod.py you can modify your manage.py file with :
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
from django.conf import settings
def main():
"""Run administrative tasks."""
if os.getenv("USER") == "webapp":
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '<project_name>.settings_preprod')
import subprocess
import ast
def get_environ_vars():
completed_process = subprocess.run(
['/opt/elasticbeanstalk/bin/get-config', 'environment'],
stdout=subprocess.PIPE,
text=True,
check=True
)
return ast.literal_eval(completed_process.stdout)
for key, value in get_environ_vars().items():
os.environ[key] = value
else:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '<project_name>.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
If you wish I have script that set up crontab from models !
Hope it will help !