Member-only story
How to Schedule Django Commands on AWS Elastic Beanstalk
An up-to-date guide to running Django commands on AWS EBS using cron jobs
Recently, I was looking to run a script once an hour that also required my Django app context. Though I did find a couple of online guides, they were either outdated or not comprehensive and aligned with the recent changes in AWS Elastic Beanstalk (EBS).
EBS allows us to run web apps such as Django in a seamless and managed way. That also means we shouldn’t set up any local cron jobs on our current, randomly assigned EC2 instances. Instead, we do it within our EBS environment.
In this guide, I’ll outline how to define your Django command, create an EBS config file, and deploy and test your newly created scheduled script.
Let’s assume our script is called update_emails.py
and its purpose is to fetch new emails for a specific Gmail account on a daily basis.
Django Command
First, let’s create our Django command.
- (optional) In case you don’t already have a
commands
directory, you’ll need to create one. In your project, under the Django app of your choice, create amanagement
directory and then acommands
directory. Make sure they’re initialized as package directories…