Deploy your Web app with AWS EC2 and AWS S3
Hi there, my name is Hary Dhimas .
This article is for you that already made your web app but don’t know how to deploy it we will using AWS EC2 and make virtual machine instance for our web server (i will be using express js for this tutorial), and we use AWS S3 to store our web client there. So here is the requirement before you proceed :
- You already have AWS account (register here if you don’t https://aws.amazon.com/)
- You already have express application (or you can clone my simple server app here https://github.com/dhimashary/server-deploy)
- Your web client is ready to deploy (well, just basic html is fine)
- This just cover how to deploy our website, so i will not explain what is EC2 , or AWS S3.
Deploying our web server with EC2
We will try to deploy our web server first,
1. Open AWS management console and choose EC2
2. Select Launch Instance to create and configure your virtual machine.
3. Configure your instance :
There is 7 step to configure your VM instance, (I will choose configuration that free tier eligible here)
Step 1 choose Ubuntu Server 18.04
Step 2 choose t2.micro
Step 3–5 just next (you can add tags on step 5)
Step 6 i will add HTTP and HTTPs to the rules
On Step 7, after clicking Launch key pair window will be prompted like below
Download the key pair , store it in secure location and proceed to launch your instance.
4. After you done creating your VM instance connect to your instance
5. There is several ways to connect to your instance, i will choose a standalone SSH client to connect. Go to where your key pair located in terminal and follow the instruction on the prompted window.
6. After SSH client connection established on your terminal, install Node js, PM2 (to make our server app stay alive, install it globally) and git clone your web server.
7. Go to your cloned repo and run npm install and then run sudo su (we need to run as root to open port 80, and then export PORT 80 so our app start listening to port 80) since in our app PORT set like this ,
const port = process.env.PORT || 3000
lastly run pm2 start app.js to start running our server.
8. Finally Our server is running ! You can access your server via IPv4 Public IP (look at step 4 Picture).
Deploying our web client with S3
Deploy your web app on AWS S3 is relatively easy, and you don’t need to prepare your subdomain, s3 will generate your subdomain based on your bucket name (if you want to use your own subdomain make sure it has the same name as your bucket).
- Go to your S3 dashboard in AWS
- Click create bucket , and the bucket configuration window will be prompted like image below
There is 4 configuration to create your bucket :
- Enter your bucket name, and region
- Make sure to uncheck the Block all public access option on step 3
- Proceed to create your bucket
3. After your bucket created, upload all your web client file here
4. After that go to properties and enable static web hosting
5. Done ! You can access your website with endpoint provided by AWS.
Thank you for reading this article !