Search code examples
djangoamazon-web-servicesdockeraws-lambdaamazon-ecs

Scheduling Weekly Django Commands for AWS ECS Docker Deployment


I have a Django project in a Docker container that is being deployed to AWS Elastic Container Service. I would like to have a Django command execute on a weekly basis, but I am unsure what is the best practice for doing this.

Is this something I can/should set up as part of the Docker/Django project itself?

Would I be better using something like AWS Lambda or Batch to schedule this? If so, how do I access this script in my Django deployment?


Solution

  • I think there are several broad strokes ideas you could use:

    1. Something completely outside of your ECS (like you already suggested)
    2. Something in ECS, using k8s (a k8s CronJob)
    3. Something inside your django project (django-crontab)
    4. A full-blown task scheduling and execution framework (django-celery)

    1 Sky's the limit!

    That's all you! There are a lot of options

    2 Kubernetes CronJob

    I've used these before and they're quite robust and reliable: https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/

    3 Django Crontab

    This is pretty simple and straightforward. This would be my pick if I had only this one thing I had to do once a week and I knew it wasn't going to grow, or only have very infrequently running jobs. https://pypi.org/project/django-crontab/

    4 Celery CronJob

    This one is a lot of work but if you end up with a lot of background tasks it can be quite worthwhile to setup as it's very inspectable and you can trigger jobs manually from the django admin.

    https://docs.celeryproject.org/en/stable/django/first-steps-with-django.html