Simple Web App
In this part we're going to end up deploying a simple bun TypeScript server, with a database, to an EC2 instance.
There will be a:
- Web app written in TypeScript
- Database (MySQL)
- Reverse proxy (Caddy)
Web App
The fact that it's a TypeScript app that runs in a bun runtime is not important. The steps are pretty much the same for any server-side application. You'll just need to modify how you compile or run the server-side code depending on which language you're using.
For example:
- A compiled language like Go, Rust, or C++ would need to be compiled before uploading to the server then run directly from the server.
- A managed language like C# or Java would need to be compiled and the .NET or Java runtime would need to be installed on the server.
- And languages like Python, Ruby, or JavaScript would need to be run through a runtime or interpreter.
But in this case, we'll be installing and using bun to run the TypeScript code.
Database
We'll be using MySQL for the database, so all the steps will be for MySQL. But the steps could easily be adjusted for any other database, as long as you have the right driver and connection string.
Reverse Proxy
We'll be using Caddy as the reverse proxy. This is a modern, fast, and secure web server that is very easy to configure. However, you could use any other reverse proxy like nginx or apache.
Steps
- First we'll setup a basic Caddy server to get a sense of how to setup a simple HTTP server on an EC2 instance.
- Then we'll setup a different EC2 instance running just a MySQL database.
- Finally we'll setup another instance running the web app, a database, and a reverse proxy.
In total, we will setup and tear down 3 EC2 instances in this section. It might seem repetative, but it's good practice for understanding how all the individual parts work. Also, being able to quickly setup an EC2 instance to test something out is a very useful skill.