AWS Tutorial

About this post

This post is a record of my learning journey through this AWS tutorial video:
https://youtu.be/Nzv-tzU-UAw?si=lvIXGK1LKYM1snyz. Aside from the content covered in the video, I also learned how to set up billing alerts to monitor my expenses, and how to clean up the resources created to avoid unnecessary charges.

⏯️ The result can be found here: https://youtu.be/UhF5I0qh2gk

Account Creation

It seems that I created my AWS account with my school account a while ago, which makes me ineligible for the free tier when I try to set up a new account with my personal email when confirming my identity.
I therefore decided to proceed with a paid account and set up billing alerts to monitor my expenses.

Setting up billing alerts

billing alert
billing alert setup
Click on “Create budget”, and we’re good to go!
(Something like this will show up in the end)
billing alert final

UPDATE

As shown below, I got alerted that my actual cost is $0.04 on the day after, which is reasonable since the pricing is per hour (and my instance was running for an hour or two)
bill
bill mail

Setting up an EC2 instance

Since HTTP through port 80 requires extra setups, port 8080 is used instead.
ec2 setup

Create S3 bucket

The site of this tutorial is hosted on an S3 bucket, which makes the bucket name part of the URL.
Note that the bucket is set to public, so the public access settings need to be adjusted.
s3 setup

An extra setup to make the site public

Edit bucket policy is required. This is because disabling “block public access” does not means the bucket or objects are public, only means than you can make them public. (referece: https://stackoverflow.com/a/70473871)

1
2
3
4
5
6
7
8
9
10
11
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mikes-macaron-market/*"
}
]
}

Create database with RDS

rds setup
Note that here we connect to the EC2 instance that we created earlier.
rds setup2

After the database is created (which takes a while), an endpoint will be provided, which is provided in the popup message or can be found in the RDS dashboard.
alt text

Connect to EC2 instance

Use “EC2 Instance Connect” to connect to the instance.

Some commands explanation

  • export S3_ACCESS_KEY=key: where key is the “Access key ID” that can be found in the csv file downloaded when creating the access key in IAM>Security credentials>Create access key.
  • export S3_SECRET_KEY=secret: where secret is the “Secret access key” that can be found in the csv file same as above.
  • export DB_PASS=pwd: where pwd is the “Master password” that can be found in the RDS dashboard or in the popup message when the database is created.
  • export DB_ENDPOINT=endpoint: where endpoint is the endpoint of the database that can be found in the RDS dashboard or in the popup message when the database is created.
  • npm start & : run the command in the background so that we can still use the terminal
  • disown: disown the job to disconnect the background job from our session

Before closing the terminal, remeber the public IP of the EC2 instance, which is needed to access the site.

Access the site

The site can be accessed through http://<the-public-ip-of-ec2-instance>:8080
Remember to specify port 8080, in my case it’s http://54.208.203.138:8080 (this IP will not work anymore since I have terminated the instance).
site

I’ve recorded the result here: https://youtu.be/UhF5I0qh2gk.
I also tried accessing the site through my phone using mobile data, and it works! See the mobile recording here: https://youtube.com/shorts/iNGrAlDeYNQ

Clean up

Remember to terminate the EC2 instance, delete the S3 bucket, and delete the RDS database to avoid unnecessary charges (which is not covered in the tutorial video, probably because it’s using a free tier account)

Terminate EC2 instance

terminate ec2

Delete security group

delete security group
Here I bumped into mutual access issue when trying to delete the security groups rds-ec2-1 and ec2-rds-1.
It is because

  • rds-ec2-1 allows inbound traffic from ec2-rds-1
  • ec2-rds-1 allows outbound traffic to rds-ec2-1
    So I deleted via console with the following steps:
  1. Open rds-ec2-1
  • Edit Inbound Rules
  • Delete the rule where Source = ec2-rds-1
  1. Open ec2-rds-1
  • Edit Outbound Rules
  • Delete the rule where Destination = rds-ec2-1

Delete S3 bucket

delete s3

Delete RDS database

delete rds