Modern APIs with FastAPI and Python Transcripts
Chapter: Deploying FastAPI on Linux with gunicorn and nginx
Lecture: Create a cloud server
0:00 Here we are inside my Digital Ocean account. Now over under these projects, we've got Talk Python and we've got this thing called Playground.
0:08 If I were to click on Talk Python, You'd see we have a whole bunch of servers that are hosting many services and databases
0:15 and all sorts of stuff going on over there. But this one is just a nice little empty space where I can work.
0:20 So this should look roughly like what you would have. Now, here's the platform as a service,
0:24 this apps thing. But what we're going to do is just create a droplet. A droplet is, you know, code word for "I'm going to create a virtual machine".
0:31 You can see you could create a server based on many different versions of the operation system. we could do FreeBSD, Fedora,
0:38 Debian and so on. And then within those you get to pick which version. I recommend if you go with Ubuntu you pick an LTS long term support version.
0:46 Otherwise, you'll stop getting updates and that won't be fun. We'd also go for containers. You can go to this place called the marketplace,
0:53 and it will let you, like, grab a pre-configured WordPress server or whatever. But that's not what we're doing.
1:00 We're gonna create a distribution, and then you pick well, what kind of server do you want? I'm gonna pick the $5 server for this one.
1:07 Now you might think, Well, this is a toy server. It's not really gonna be able to do much. But these servers can actually handle a lot.
1:14 And Python does not put much of a load on these servers. It depends on what you're doing,
1:19 but this little wimpy server, unless you have got some kind of crazy computation stuff going on, if it's a relatively standard Web application,
1:29 it should be able to handle multiple millions of requests per month. So it's actually a pretty good starting point. The next thing we're gonna pick,
1:36 we could add an extra hard drive, we don't care about that. You might need that, if you had say, like, tons of data in a database,
1:41 you want to put that over there. Could make sense. We're not going to do that. Now you want to pick a data center that makes the most sense for the
1:48 consumers of your application. For many of us, that probably means either Europe or the East coast of the United States.
1:56 For us, our servers are in New York City. The reason is that's good for all of the United States
2:02 and North America. It's also pretty good for Europe because it's a straight shot across the ocean, so that covers many of our users.
2:11 We also have people all over the world, you know, places that are far from there, like Australia, New Zealand, which is not ideal.
2:17 But we got to pick one place and just for us, East Coast of the US made a lot of sense. However, I'm on the West Coast.
2:23 So just to keep things quick as local, we're gonna pick this, right? So you pick the one here that makes the most sense for you.
2:30 Just be careful. If you're gonna create multiple servers like a Web server and a database server and you want them to talk to each other,
2:36 it's much, much better If they're in the same data center. We could use VPC, virtual private networking.
2:42 It's on by default, but we're not going to do anything with it. Might as well turn on monitoring.
2:46 This lets us look at the server through some of the management tools here. We're going to use an ssh key which allows us to just log in,
2:54 and just go ahead and type "ssh" and go and register the ssh key. We won't have any username or password to mess with. Going to turn them all on.
3:03 Here's the project it's gonna go into, in playground. You could turn on backups, we're not doing that. So watch how quick this is.
3:09 Oh, I should have given it a name. Oh well. Yeah, be sure to give us a better name,
3:13 but I'm gonna leave this going in real time so you can see how long it takes. So I'm not going to cut anything out here.
3:18 I'll just keep kind of rambling on. It should take usually about 30 seconds. So virtual machine is there. I think it's probably starting right now.
3:28 Maybe some final startup script for the first time of running, and wait for it. That's it. I don't know, what was that? About 30 seconds.
3:35 We can go back and check. But not very long. And so now we have a virtual machine over here. We just click that to copy the IP address.
3:43 Ultimately, you want to map a domain name over there. But basically we're done with Digital Ocean.
3:48 That's it. That was all of the Digital Ocean that we care about.