# AWS 共學 Week2: EC2 Instance Storage
###### tags: AWS, EC2, EBS, AMI
## Rick: 聊聊 EBS (Elastic Block Store) 的特性,使用情境
- 即使 EC2 被關閉了,EBS 可以被保留下來,供以後使用
- Volume Type
- gp2 / gp3 General Purpose (can use as Root Volume)
- io1 / io2 High Performance (can use as Root Volume)
- st1 low cost
- sc1 lowest cost
- Mount to 1 Instance only (Multi-attach io1 & io2 only)
- 把它當作 Network USB Stick,可插過來這個 EC2,也可以插過去那個 EC2
- 但僅限同 AZ
- 免費 30 GB General Purpose (只有 [12個月]((https://aws.amazon.com/ebs/)))
- 要注意 **Free Tier** 跟斯斯一樣有兩種
1. 註冊後的 12 個月免費
2. 永久免費
- EBS 速度稍慢
## Rick: 聊聊 AMI (Amazon Machine Image) 的特性,使用情境
- 開一台新的 EC2 有時候要裝一堆有的沒的
- 客制化 EC2 boot / configuration
- AMI 是可以在 Amazon Market Place 賣的! ($$$) 但有人這麼懶嗎? 是甚麼樣的 AMI 在市面上賣?
- 有甚麼是值得丟進 AMI 的? 實務上的實用案例?
## Eric: Create Custom AMI Demo
[AMI Hands On](https://www.udemy.com/course/aws-certified-solutions-architect-associate-saa-c03/learn/lecture/26098284#overview)
[生成 Key Pair](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html)
```shell
echo 'This should be seen in new EC2 instance' > hello.txt
```
使用以下 command 來列出所有 instances (generated by [ChatGPT](https://sharegpt.com/c/uOcZVcE))
```shell
$ aws ec2 describe-instances --query 'Reservations[].Instances[].{Name: Tags[?Key==`Name`].Value|[0],InstanceId: InstanceId,InstanceType: InstanceType,State: State.Name,PublicIP: PublicIpAddress,PrivateIP: PrivateIpAddress,AvailabilityZone: Placement.AvailabilityZone,LaunchTime: LaunchTime,KeyPairName: KeyName}'
```
會得到
```shell
[
{
"Name": null,
"InstanceId": "xxx",
"InstanceType": "t2.micro",
"State": "running",
"PublicIP": "xxx",
"PrivateIP": "xxx",
"AvailabilityZone": "ap-northeast-1c",
"LaunchTime": "2023-03-13T05:47:17+00:00",
"KeyPairName": "my-key-pair"
}
]
```
## Rick: 丟假設性問題,把討論引導至 Init EC2 with Custom AMI
- 好的,我們現在有自製的 AMI,可以丟上去 Market Place 開賣
- 那開一個新的 EC2,速度真的會變快嗎
## Eric: Init EC2 with Custom AMI
## Eric: Create EBS Snapshot
## Rick: 聊聊 EFS (Elastic File System) 的特性,使用情境
- Linux AMI only
- NFS Protocol
- Performance
- General Purpose
- Max I/O
- Bursting
- Provisioned
- Elastic
- Storage Class
- Standard
- Infrequent Access
- EBS vs EFS
| | EBS (Elastic Block Store) | EFS (Elastic File System) |
| ----------- | -------------------------- | --------------------------------------------- |
| AZ | 只能同 AZ | 可以跨 AZ |
| Mouting | 只有io系列可以multi-attach | 天生設計來 multi-attach 兼劈腿跨 AZ |
| OS | 都可 | Linux Only |
| Price | 較低 | 普遍較高,但有 Infrequent Access 是全部最低價 |
| Performance | 請看最新的文件* | 請看最新的文件* |
\* Amazon 固定升級硬體,以最新文件為準
## Eric: EFS (Elastic File System) Demo
- Test EFS A (AZ_A)
- Test EFS C (AZ_C)
- Connect them with EFS