Better Programming

Advice for programmers.

Member-only story

How to Schedule Django Commands on AWS Elastic Beanstalk

Sahar Mor
3 min readDec 22, 2020

--

Django and Elastic Beanstalk
Photo by the author.

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.

  1. (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 a management directory and then a commands directory. Make sure they’re initialized as package directories…

--

--

Sahar Mor
Sahar Mor

Written by Sahar Mor

Bringing the latest in AI to the mass through writings and Github repos | aitidbits.substack.com - generative AI weekly roundup in <2 min