Running a HTTPS Python Server on EC2 in 5 Minutes

No Docker needed. Just a simplest setup you can get to launching and getting your dopamine hit.

pancy
4 min readDec 30, 2020

I have come to grown very wary of all the extra layers of technologies (I’m looking at you, Docker) that had compounded onto launching a piece of software on the web. Many will frown upon you if you don’t containerize your app in 2021, but the truth is for most use cases, containers are just a waste of time and headspace compared to just doing it the old-school way.

Here I’m going to walk you through setting up a running HTTPS API server in Python using FastAPI (trust me, Flask is so 2008) and Caddy web server (this one is a total replacement to NGINX and gives you automatic HTTPS, saving you from the pain of setting up TLS certificate).

🤷 Tips: Hold it if you are tempted to Dockerize your app for your first Product Hunt launch or Hacker News show and tell. You’re distracted.

Setting Up

  1. Launch a t2.micro EC2 instance on AWS. I’ll be using Amazon Linux 2 in this example, but you can stick to Ubuntu if you like.
  2. Download a .pem keyfile from the instance in order to SSH into it.
  3. In the instance security group, edit the in-bound rule to open port 80 and 443 to public like this:
Screenshot of EC2 Inbound rules table that open port 80 (HTTP) and port 443 (HTTPS) externally.

4. SSH into the instance with:

ssh -i my-key.pem ec2-user@<your-instance-public-dns-name>

💁‍♀️ Your EC2 instance public DNS name usually ends with .compute.amazonaws.com . Note that ec2-user is currently a default user name for AWS Amazon Linux 2 instance.

5. Install Caddy web server with

yum install yum-plugin-copr
yum copr enable @caddy/caddy
yum install caddy

This installation might run Caddy server process in the background right away. To be sure, run caddy stop .

6. Optionally, you may need to grant low-numbered port access to non-root binary, which is caddy in this case. This allows Caddy web server to…

Read the full story with a free account.

The author made this story available to Medium members only.
Sign up to read this one for free.

Or, continue in mobile web

Already have an account? Sign in

pancy

I’m interested in Web3 and machine learning, and helping ambitious people. I like programming in Ocaml and Rust. I angel invest sometimes.