The very first version of ZipLink was built with NextJs, Prisma (an ORM), and MySql on PlanetScale. I deployed it on vercel. But not so long after I figured out that the API calls were taking much longer (sometimes even up to 7s for shortening an URL😒), which was not the case when developing the site locally. So I decided to dockerize my app and deploy it to AWS LightSail to check if that improved or not.
How to create a MySQL container using docker
Connecting to a Linux server in AWS from Windows using PuTTY
Proxy server and reverse proxy server
Create a Linux server in the AWS lightsail
Connect to the server using an ssh client. For Windows, it could be PuTTY.
Install docker, docker-compose, node, and all the necessary software on the server.
Follow the links for docker and docker-compose installation:
If you don't already have a NextJs app, you can follow this and this.
For an already existing app, we will have to write two Docker files: one for our NextJs app and the other for the Nginx server, which we will use as a reverse proxy for our site to handle the SSL connection. First, we will need our certificate
and certificate_key
files. To create these, follow the following link:
You have to move your certificate and certificate_key files inside the directory of the app, say inside the nginx/certs/
folder, and provide the path accordingly in the nginx.conf
file.
I have used vercel as my domain name server and configured the A and TXT records for my site there.
Finally, use docker-compose up - - build -d
to deploy your dockerized NextJs app.
To get the site down, we have to use docker-compose down
Deploying the site on AWS improved the API response time a lot. The response time of shortening the URL for the first time has gone down to ~1s and after that, it takes ~600ms. I believe connecting to PlanetScale for the first time is what’s causing the bigger response time. Once the connection is made, the API calls become faster. One solution to this problem can be to dockerize a MySql server and deploy it to AWS along with the NextJs app.
Site: go.sadia.dev
Github: https://github.com/Sadia1505076/url_shortener_with_docker_aws