---
title: AWS Introduction
tags: AWS
---
# AWS Introduction
## Register an AWS account
<iframe width="560" height="315" src="https://www.youtube.com/embed/oUoJBayrJT4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
## AWS RDS -- Creating and connecting a PostgreSQL database with AWS RDS via pgAdmin
:::danger
If you get connection failed, please check whether you have set **inbound rules** and **outbound rules**!!!
:::
* [AWS RDS](https://towardsdatascience.com/creating-and-connecting-a-postgresql-database-with-amazons-relational-database-service-rds-dcc9db0cd37f "Creating and connecting a PostgreSQL database with AWS RDS")
## AWS Elastic Beanstalk -- Deploy a web app, this service will automatically generate an instance on AWS EC2 for you

### 1. Go to AWS Elastic Beanstalk page
* Click on ==Services==
* Click on ==Elastic Beanstalk==
### 2. Create a new environment

### 3. Select environment tier

* Click on ==Web server environment==
* Click on ==Select==
### 4. Enter your app information
* Enter your app name
* The environment name is auto-generated, so after filling in your app name, we can just scroll down to ==Platform== part

* Choose ==Node.js== here as we prepared an app written in Node.js (a framework called Express)

* Scroll down to ==Application code==
* [download the demo file here](https://drive.google.com/file/d/12s53bDon8eYmnBfeC--R0k5PJIcCLOkF/view?usp=sharing "download demo file")
* Click on ==Choose file== and choose the demo file you have just downloaded

* ==Version label==, here you can fill in an unique name for this version of codes you upload
:::danger
file **Maximum size** `512 MB`
:::
* ==Configure more options==, here you can modify more detailed settings like load balancer, instances and much much more... We can just skip that and hit ==Create environment==

* As you see, it will really take a few minutes, so just be patient and wait

### 5. Now you can click on the link to see your app

:::info
When you don't provide a Procfile, Elastic Beanstalk runs npm start if you provide a **package.json** file. If you don't provide that either, Elastic Beanstalk looks for the file **app.js** or **server.js**, in this order, and runs it.
:::
:::danger
If the Health status is not **Ok**, you may click on **Configuration** on the left hand site, click on **Edit** of **Software**, scroll down to the bottom of the page, and you will see **Environment properties**, fill in ==port information==, then click on ==Apply==. Wait a few minutes, the app will restart.
:::
```Javascript=59
const PORT = process.env.PORT || 8081;
app.listen(PORT, () => console.log('Server running on port ${PORT}'));
```

## AWS Certificate Manager -- Get a SSL/TSL certificate and use it on an EC2 instance behind an ALB
* When you click on the link, you will see this url is not secure, so we gonna get a SSL certificate

### 1. Apply a domain name
#### 1.1 [Apply here](http://www.freenom.com/en/index.html "It's free and no credit card needed")
:::info
[More information in Chinese](https://zhuanlan.zhihu.com/p/109553641 "中文資訊")
:::
#### 1.2
* Enter a domain name you would like to use
* Hit ==Check Availability== to see if it's available
* Hit ==Get it now!==, and it will become ==Selected==
* Hit ==Checkout==

#### 1.3 Go to AWS EC2 page to get some information
* Click on ==Instances== on the left
* Tick the name that you would like to see it's detail
* Copy it's ==Public IPv4 address==, like **my IP** here is 18.181.219.41

#### 1.4 Go back to freenom site
* Paste your IP in these 2 columns
* Remember to choose 12 months free (It's only 3 months by default)
* Hit ==Continue==

#### 1.5

* Tick I have read and agree to the Terms & conditins
* Hit ==Complete Order==
#### 1.6 Then you are good to go!!

* You can go to **Services -> My Domains** to check out all of your domains

### 2. Search for Certificate Manager

### 3. Click on ==Get started== under Provision certificates

### 4. Click on ==Request a public certificate==, then click on ==Request a certificate==

### 5. Fill the domain name we have just got from freenom
* Then click on ==Next==


### 6. Leave the default option as DNS validation
* Just click on ==Next==

### 7. Click on ==Review==

### 8. Click on ==Confirm and request==

### 9. Pause here

### 10. Go to AWS Route 53 page (open in a new tab)

* Click on ==Create hosted zone==

### 11. Fill in domain name, and click on ==Create hosted zone==

### 12. Click on ==Create record==

### 13. Leave default setting, and click on ==Next==

### 14. Click on ==Define simple record==

### 15. Go back to AWS Certificate Manager page, we need to copy the name and the value below

### 16. Paste here
#### 16.1 The name from **15.** , remember to remove the last part of the url as it is repeated
#### 16.2 Select ==IP address or another value depending onthe record type==
#### 16.3 The value from **15.**
#### 16.4 Select ==CNAME -- Routes traffic to another domain name and to some AWS resouces==
#### 16.5 Click on ==Define simple record==

### 17. Our record is successfully created!!

### 18. Go back to step 9. and click on ==Continue==

### 19. What? Pending validation!?

---
## Sources
<iframe width="560" height="315" src="https://www.youtube.com/embed/ubCNZRNjhyo" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe width="560" height="315" src="https://www.youtube.com/embed/bWPTq8z1vFY" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<iframe width="560" height="315" src="https://www.youtube.com/embed/b0g-FJ5Zbb8" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
[Chinese Source](https://medium.com/@chihsuan/aws-load-balance-%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%E4%BB%8B%E7%B4%B9-33c30a59b596)