graphene-django
Published October 20, 2021
This video features Dane Hillard at DjangoCon US 2018 in San Diego, California, USA.
DjangoCon US 2018 - Serverless Django with Zappa by Dane Hillard
A common set of considerations when planning to release a new application are around hosting and resources:
Which platforms will support my app?
What OS should I use?
What WSGI server should I use?
How much memory and CPU do I need?
Zappa, a framework for running serverless WSGI applications on top of AWS Lambda, can help address these and other questions around application deployment. With some configuration (as code), Zappa can get you up and running quickly, letting you focus on developing the application instead of the infrastructure.
In this talk we’ll go through some of these kinds of questions to see how they might be answered in traditional solutions and then see how Zappa handles them. We’ll also talk about a few specific configuration options for handling SSL certificates and running Django commands on the Zappa-deployed application.
This talk was presented at: https://2019.djangocon.us/talks/djang...
LINKS:
Follow Dane Hillard 👇
On Twitter: https://twitter.com/easyaspython
Official homepage: https://easyaspython.com
Follow DjangCon US 👇
https://twitter.com/djangocon
Follow DEFNA 👇
https://twitter.com/defnado
https://www.defna.org/
Dane Hillard explains how Zappa deploys Django applications as serverless AWS services. The setup replaces self-managed web servers, application workers, certificates, and static-file storage with API Gateway, Lambda, Amazon Certificate Manager, and S3, while Lambda handles scaling and charges are based on execution time. He demonstrates the Zappa configuration and deployment workflow, then covers logging, management commands, scheduled tasks, packaging optimisations, automation, database choices, cost, and cold-start latency.
Summarised automatically from the transcript.
Automatically transcribed, so expect mistakes in names and technical terms.
Speaker 1: Yeah, so thank you. As she said, my name's Dane and I am a web developer at Ithaca. You may know us from JSTOR. org. It's an academic research platform. And on Twitter, I'm Easy as Python. And GitHub, I'm Dane AH. Uh so feel free to connect. Uh and I am here today to talk to you about Zappa. Uh well not not this Zappa, uh although he warrants a talk All on his own, many talks perhaps, uh, but Zappa nonetheless. Um and specifically uh how we can uh do serverless Django with Zappa. And specifically, I mean this Zappa. It's a framework written by a guy named Rich Jones.
Speaker 1: And what it really does is let you do serverless AWS deployments for Python applications. And so during this talk, I'm going to kind of emphasize these pieces here in bold colors. So what we're gonna do is talk about each of those in a little bit of detail. So we'll talk about servers, what a server really is, and what the less part of serverless really means. And then some specifics about Amazon Web Services and how you go about actually deploying an application there. So first, let's talk a little bit about servers. They are , at their core, a thing that a user can make a request to
Speaker 1: and receive a response from as a result. And uh so many of you being Django developers are probably intimately familiar with this idea. Um, but what really happens and how do how do we achieve that workflow along the way? Um So you have a server and when a request comes in, uh it typically gets handled at first by a web server which knows how to speak HTTP. And then that passes it along to something like GUnicorn, which is a way to translate an HTTP request into something that Python can understand. and ultimately it will end up at uh your Django application.
Speaker 1: And there's there's some additional things that you'll probably be using if you're doing any kind of dynamic application. Um you'll probably need to talk to a database. You'll probably need static assets to style your pages. And you'll probably want a certificate of some kind if you want to be working over HTTPS. And as you get more traffic to your application, you want to be able to handle more concurrent requests. So you'll start making more processes for your Django application, and each of those can handle a request at a time. And then when your server inevitably can't handle the load and falls over, you decide maybe you'll make several of those servers and put them behind a load balancer.
Speaker 1: So you you start it you start scaling horizontally uh to handle all this traffic, um and that's fine Uh but if you're like me and don't really have time to do a lot of automation of your your DevOps and things like that, managing all of these servers can get uh kind of tedious and kind of frustrating. Um So how do we do how do we do less? Um uh like Ron Swanson. There has to be a better way and we want to free ourselves of the earthly burden of all this machinery. Uh what less really means to me in in serverless, which is sort of a marketing buzzword, uh, is that you do less management and you do less uh
Speaker 1: sort of fiddling with all of these moving parts and try to find a way to more easily manage all of these things in an automated fashion and abstract some of those things so that you don't have to see the the hairy details every day. Um so this again is is what uh a server might look like and We want to find a way to basically take these different pieces that are on the server and get them off of the server so that we don't have to Deal with them anymore or or can deal with them in a better way. So let's start with uh cert. Um how many of you are familiar with Let's Encrypt? Great, that's like half of you or
Speaker 1: so. Um it essentially lets you um much more easily Uh set up a cert and serve your website over HTTPS to the world. And Amazon also has an answer to this called Amazon Certificate Manager. So for the sake of argument, let's offload that to the Amazon certificate manager. This way we can just easily create a certificate. in the in the console and uh apply it to the resources that we want that certificate to be on. So that's that's sort of locked in. And now that is off of our server. And then the next thing is those static assets.
Speaker 1: It could be the media that your users are uploading as well. So right now you might store those on your server at least temporarily when they are uploaded or when you do a collect static during your deployment. But we can store those in Amazon as well. It has a thing called simple storage service. And you can refer to those those different files by their By their object basically in S3. Um so let's lock that in. And the last the last remaining pieces are really the parts that are important to the request response lifecycle that leads from HTTP request down to a Python translation down to Django.
Speaker 1: Uh so how do we get rid of that stuff? That seems kind of tricky. Um so one way we could imagine doing this is with some other Amazon tools. So we're taking away the job of routing from Nginx and using instead Amazon's API gateway and we're taking the job of uh translating requests from HTTP to Python away and uh using Lambda to do that. So how many of you have heard of Lambda? Okay, that's like most of you. So that's great. Lambda is Amazon's functions as a service, essentially. And
Speaker 1: what they do is let you respond to a request uh by executing some function And uh it would be great because it would be great if we could use Django uh as the underlying function for this. Um And effectively get rid of our server. So as you can see, sort of from this last transition, we've kind of freed ourselves of the need for this server wrapping all of our code. So how how do we get there? And how more importantly, how do we respond to more activity in our application? Um so let's let's talk a little bit about what the details are under the hood in AWS.
Speaker 1: Um so imagine we are creating a website where we can post pictures of puppies, uh all the best puppers. What we need for our for our certificate is to create uh a certificate in Amazon Certificate Manager. And then what that lets us do is reference that certificate with an Amazon resource number or an ARN. So that long string EC is uh the identifier basically for that cert. By the way, uh bestbubbers. com still available, uh so you should buy that. And then uh for our static assets, uh, we need a a bucket to store those in in S3.
Speaker 1: And so we're gonna tell we're gonna tell Zappa how to uh where to put its stuff um by referencing that bucket name as well. And the next piece, which is sort of the crux of it, is that we need to put our Django application into Lambda. And there's sort of this wrapper around it that does that WISGI translation for us. And then Lambda can handle all of that horizontal scaling that we talked about earlier. So uh once we once we're able to do that, we're sort of home free. Uh and and with the API gateway, we can manage our different environments. Um and and route requests for different domains
Speaker 1: to different sets of applications. So to recap, uh Amazon Certificate Manager for SSL certs and S3 for static file storage, and if you're feeling really ambitious. You can put CloudFront in front of it to get a globally distributed set of static files to speed up delivery to users And then uh Lambda for our request workers and the API gateway to route uh requests to different applications. Uh so the next step uh is deployment. Um hopefully you can do it the first time. Uh so uh the way
Speaker 1: the way that we do this with Zappa uh is basically to uh initialize our configuration and set up the details in our Zappa settings. So how do we do this? Um In order to get your application set up with Zappa , like here, I've just basically started with uh Django Start Project Best Puppers. So you have your single application module package rather with your settings and your URL patterns and your WISGI. py as well as your manage. py. Uh you'll also need your AWS credentials listed. Um
Speaker 1: and uh the way I prefer to do this is to have a different profile for each of my projects, um even if they end up using similar set of credentials. So once you have those two things in place, you can just pip install Zappa and run Zappa init. And what that's going to do is detect your application type. So it's not actually just Django that is supported, it's really any WISGI application and even some non-WSGI applications, if I if I remember correctly. And then it will create that S3 bucket so that it can upload artifacts for your application. And then it will create this zappa settings. json file. And uh at first that'll look probably something like this.
Speaker 1: Uh so you have a staging environment, uh maybe a production environment. Um And each one will have the AWS region that that is deployed to, and then it will automatically figure out your Django settings module And the profile name is referring to that AWS credentials profile. And then the project name is your Django project, and the S3 bucket is that bucket name that we talked about earlier. So then now that you've got all this configuration in place, uh you're sort of ready to do your first deployment. It's it's pretty much that easy. So you run Zappa deploy staging, and staging is the name
Speaker 1: of that environment from your sat from your Zappa settings JSON. And what that'll do is uh well I won't I won't make you read all of this code here or this output here, but What happens is that it will freeze your Python requirements along with all of your application code into a single zip file. And then it'll upload that zip file to S3 into that bucket. And then it will create API gateway routes for you. And it will create Lambda functions that ultimately point to the Django view code that you need to execute. in response to requests and then hook the API gateway to those Lambda functions. And importantly it prints out the URL you can visit your application at at the end.
Speaker 1: Um it's some long randomly generated string of characters, followed by this execute API uh US East One or whichever region you're in, Amazon AWS. com and then slash your environment. Um And updating your application is quite similar. Um again it's it's Downloading all of your dependencies, packaging them up as a zip, uploading that to S3, uh, and then since you're updating your application, it'll update the Lambda and uh redeploy the API gateway. And then uh uh give you the URL to visit that again. So the next step after this is getting your certs in order.
Speaker 1: And fortunately that is very easy too. So once you've created a certificate, an Amazon certificate manager, uh you can take that ARN, that AWS resource manager or resource number string and specify it in your environment as the certificate ARN and then tell it the domain that you want to certify. And then you just run Zappa certify stagey. And that will certify the stag that you specified using the cert that you specified And then uh through this you also get uh log storage and tailing. Uh so you can See what's happening in your application in real time as well as persist those logs for later use.
Speaker 1: Uh you also get management commands and even the ability to run raw Python against your Lambda. uh against your environment where the lambda lives. And as as you should know from Lambda, you get auto-scaling uh to meet your request load. Some points there though are to watch out for concurrency and cold start time. You can read more about that. There's a good article I could point you to later. Um but essentially just if you're if you're trying to serve very fast requests um you may want to look into that first And importantly, you'll probably have a way lower AWS bill because you don't have servers running when they're not serving any requests.
Speaker 1: So a request comes in, it is managed by that Lambda function, and as soon as that response is sent, that Lambda goes away. And you only pay for the execution time uh of that request lifecycle. And a couple of odds and ends to our like serverless database options. Amazon did release Aurora Serverless recently. That's their MySQL compatible product. And it's so it's a managed solution. But the cost is really comparable to any of their other database solutions at the moment. So there wouldn't necessarily be a price gain there, although you might still like the uh the managed solution facet of it. There's also DynamoDB, but
Speaker 1: that's a NoSQL solution, and I don't know, at least at the time of writing this talk, of any uh of any production ready drivers for Django for using Dynamo DB. There are a couple of other options out there that are not necessarily Django specific, that are also not relational databases, but uh might still persist data for you in a way that's that's useful to you. Um and then you can also run asynchronous tasks. So Zappa can actually run functions from your code on a schedule if you like. You can specify things in like a cron syntax and say every four hours please run this thing. If you wanted to do uh celery workers and things like that.
Speaker 1: you'd you'd have to look into that yourself because that's not a domain I'm familiar with. But um you can also split your application into separate lambdas if you like, if you really need. uh sort of separate asynchronous behavior. Uh and long-running lambdas aren't super well supported, although I did see that AWS recently upped the uh execution limit to 15 minutes. Um I think it was previously five. So you've got triple the time to do what you need to do. So some tips are that you would Probably want to exclude most of your unneeded files. Uh node modules is huge. Um I mean it's it's I don't know.
Speaker 1: You d you don't want to ship more than you have to. So like node modules, if you use PyCharm, uh your dot idea folder. And if you are uploading media files locally, you probably want to exclude that directory too. And it just reduces the zip file size so it can zip it faster and ship it faster. uh when you go to deploy. Um and then the other major tip I have is that you should automate your process. Um You I there's there's a number of options out there. A lot of people use fabric. Uh I personally use npm scripts because I'm already using Webpack for my static assets, um, so I have a few scripts. already. Um so my package JSON
Speaker 1: looks something like this. Um that's a lot of stuff. But if you uh if you want to know more about this, uh I'm happy to like show you this file and and talk about all the parts of it uh in the hall. Um and what it essentially allows me to do is deploy my Django application by just running npm run deploy dash dash stage equals production So that's basically all I have. And if you'd like to, like I said, see more of this or talk about anything specific or see a live demo. I'm happy to do that. Um and here's my contact info again. So thanks.
Speaker 2: Hi, thanks for the presentation. What are some of the cost considerations for performance? So how would you compare you pay for every invocation. of the Lambda function that's a small price individually, how would that compare to having your own EC2 instance?
Speaker 1: Yeah, good question. Um so I was previously running uh four applications on an EC2 instance and spending something around fifty dollars a month. I I don't remember the the EC2 instance size that I was using. Um but I'm essentially paying zero dollars per month now. Uh and Amazon gives you something like three and a half million invocations free per month. Um so if you're If you're at sort of a a hobby level amount of traffic, uh I would say there's almost no likelihood that it's going to be more expensive. Um there's certainly gonna be a break-even point there if you're If you're getting so many requests that your Lambda is essentially running all the time, uh I could definitely see that that might
Speaker 1: um perhaps even outrun your EC2 cost. Um definitely a consideration. Yeah. Good question.
Speaker 3: Hi. Uh did uh does Zappa also help you um when you said it goes to the assets goes to S three, does that do it automatically when you collect asset, does it go to S three or do you have to
Speaker 1: Yeah, good question. So Zapple will not do that for you. There are a couple of really good solutions out there for putting your static assets into S3. There's a library called Django Storages. And it just takes a few uh small pieces of configuration, like adding some settings to your settings. py. uh and maybe creating the buckets yourself initially. But you can essentially collect your static files and upload your media files directly to S3 using Django storages. So that's how I'm doing it currently
Speaker 4: Uh you mentioned some serverless database options. How does that compare to like a standard RDS instance?
Speaker 1: Can you clarify your question? Uh
Speaker 4: you mentioned that uh Aurora and uh Dynamo DB and under serverless databases uh in the talk. Um I just want to know if that's any if there's anything special about that for using with Lambda as compared to like an RDS Postgres instance.
Speaker 1: I see. I mean uh Aurora again is like MySQL compatible, so if you're already using MySQL, you can probably switch to Aurora pretty easily. Uh you have to migrate your data and stuff obviously, but um I think the serverless aspect of their Aurora product is really just them saying we have a managed solution for this instead of you having to go and click and create an RDS instance yourself and run backups and make sure that It's handling the load that you're getting. So it also manages that horizontal scaling. So if you're if you're having a lot of database reads, it'll scale out for you. But in terms of sort of how you interact with the database,
Speaker 1: for Aurora at least I don't imagine there's a difference. If you went to DynamoDB or some other non-relational database, that would be a more significant shift. Does that answer your question? All right, cool.
Speaker 4: Thanks for your talk.
Speaker 5: Can you tell us about the latency per request and are you aware of any factors that change that latency depending on complexity of your slug or output size?
Speaker 1: Yeah, it's not something I've delved super far into, to be honest, but uh anecdotally, uh, on a totally cold start, uh I have websites uh again receiving like hobby levels of traffic. But They take maybe a couple seconds to load if I haven't hit them in a while. And then subsequent requests are essentially instantaneous as far as I can I can find. feel. Uh I could show you just real quick like uh maybe I can't. Here we go. Um Sorry, multiple desktops. Well, I can show I'm I'm happy to show you in the hallway, but um yeah, it's quick loading.
Speaker 6: All right, so we're about out of time. Thank you so much, Dane.
In this context, serverless means managing fewer servers and infrastructure details rather than eliminating servers entirely. AWS abstracts and automates components such as routing, request handling, scaling, certificates, and file storage.
Discussed at 3:28Zappa packages the Django application and its dependencies, uploads them to S3, creates Lambda functions and API Gateway routes, and connects requests to the Django WSGI application. Lambda handles horizontal scaling, while services such as Certificate Manager and S3 can handle HTTPS and static or media files.
Discussed at 10:26Install Zappa, configure AWS credentials, run `zappa init` to create the deployment settings, and then run `zappa deploy <environment>`. Zappa packages the code, uploads it, creates or updates the Lambda and API Gateway resources, and prints the application URL.
Discussed at 11:12For the speaker, moving four applications from an EC2 instance costing about $50 per month to Lambda reduced the cost to essentially zero, helped by AWS's free monthly invocation allowance. At high traffic levels, where Lambda runs nearly continuously, it could become more expensive than EC2.
Discussed at 20:00No. The speaker uses Django Storages, with a small amount of Django configuration, to collect static files and upload static and media files to an S3 bucket.
Discussed at 21:08Aurora Serverless is a managed, MySQL-compatible option that handles scaling and operational tasks such as backups instead of requiring you to manage an RDS instance yourself. The way an application interacts with Aurora is otherwise broadly similar; switching to DynamoDB or another non-relational database is a much bigger change.
Discussed at 22:06A totally cold Lambda start may take a couple of seconds for a low-traffic site. Once the function is warm, subsequent requests feel essentially instantaneous to the speaker.
Discussed at 23:15Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.
Published July 15, 2026
Published July 15, 2026
Published July 15, 2026
Published July 15, 2026
Published July 15, 2026
Published July 14, 2026