Django running on Azure App Service & Serverless CosmosDB

Brian Horakh
1 min readMar 19, 2021

--

I’ve got an application deployed on django — that accepts webhooks for ecommerce orders and sends them via AS2/EDIFACT to a drop ship supplier. (It also does a few other things like check a google sheet to see if a SKU matches, blah blah)

But generally it’s used infrequently, so serverless is a perfect use case. Unfortunately Azure only offers a serverless version of Windows server which takes more than a minute to startup (so it’s not really viable). I also tried to get MariaDB as a docker image, but that was also ~60 seconds for a cold startup.

So now we’ try CosmosDB & Djongo, first went to Azure Portal and created a serverless cosmos and went to the Python credentials

Following the instructions.

https://github.com/nesdis/djongo

pip install djongoDATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'your-db-name',
'CLIENT': {
'host': 'your-db-host',
}
}
}

Going to try and copy the databases using dumpdata & loaddata

https://stackoverflow.com/questions/48031744/migrate-existing-live-django-site-from-one-server-to-another-along-with-user-rec/54383307

Ultimately got this working by using a settings.py that had the full CosmosDB connection string embeded in CLIENT:{ ‘host’:’ mongodb://azure-credentials’} and nothing else.

Unfortunately pyas2 stores it’s certificate data in binary format and that isn’t compatible with jongo at all .. so that’s not gonna work either.

--

--