AWS EC2(1) - 개요
1. Billing DashBoard
- root 계정에서만 해당 내용을 볼 수 있음
- Budget 메뉴에서 미리 비용 추적이 가능
⇒ 즉, 사용자가 지정한 Budget에 대해 약 85%나 100%에 도달하게되면, 사용자가 지정한 email로 경고 알람이 가게 된다.
1) your actual spend reaches 85%
2) your actual spend reaches 100%
3) if your forecasted spend is expected to reach 100%.
2. Amazon EC2 - Basics
- EC2 is one of the most popular of AWS’ offering ⇒ AWS에서 제공하는 가장 유명한 서비스
EC2 = Elastic Compute Cloud = Infrastructure as a Service
⇒ Elastic Compute Cloud = IaaS
- It mainly consists in the capability of :
- Renting virtual machines (EC2) ⇒ 가상 머신을 빌려서 사용 가능
- Storing data on virtual drives (EBS) ⇒ 가상 저장소에 데이터를 저장
- Distributing load across machines (ELB) ⇒ 장비간의 부하를 분산
- Scaling the services using an auto-scaling group (ASG) ⇒ auto-scaling을 이용한 서비스 사이즈 증대
Knowing EC2 is fundamental to understand how the Cloud works
⇒ EC2에 대해 안다는 것은, cloud가 어떻게 동작하는 지 그 기초를 이해한다는 것
3. EC2 sizing & configuration options
- Operating System (OS): Linux, Windows or Mac OS ⇒ OS에는 Linux, Windows, MacOS등이 존재
- How much compute power & cores (CPU)
- How much random-access memory (RAM)
- How much storage space:
- Network-attached (EBS & EFS)
- hardware (EC2 Instance Store)
- Network card: speed of the card, Public IP address ⇒ 네트워크 카드 : Public IP나 card의 속도
- Firewall rules: security group ⇒ 방화벽 규칙 : security group
- Bootstrap script (configure at first launch): EC2 User Data ⇒ 첫 launch시 작동시킬 bootstrap 스크립트
4. EC2 User Data
- It is possible to bootstrap our instances using an EC2 User data script ⇒ EC2 user data Script를 이용하여 instance에 bootstrap 설정이 가능
- bootstrapping means launching commands when a machine starts ⇒ bootstrapping이란 EC2 머신 작동 시에, 발동되는 커맨드를 말한다
- That script is only run once at the instance first start ⇒ 이 스크립트는 오직 인스턴스 첫 시작시에만 발동된다
- EC2 user data is used to automate boot tasks such as:
- Installing updates (업데이트 설치)
- Installing software (소프트웨어 설치)
- Downloading common files from the internet (인터넷에서 파일 다운로드)
- Anything you can think of
- The EC2 User Data Script runs with the root user ⇒ EC2 User Data 스크립트는 root user로 작동시킨다
5. EC2 Instance Type
- You can use different types of EC2 instances that are optimised for different use cases (https://aws.amazon.com/ec2/instance-types/)
- AWS has the following naming convention
- m5.2xlarge
- m: instance class (인스턴스 클래스)
- 5: generation (AWS improves them over time) (세대, AWS 업데이트 할때마다 증가할 것 이다)
2xlarge: size within the instance class (인스턴스 클래스에 대한 사이즈)
Instance Type (인스턴스 타입)
1) General Purpose
2) Compute Optimized
3) Memory Optimized
4) Storage Optimized
- General Purpose
- Great for a diversity of workloads such as web servers or code repositories ⇒ web 서버나 code repo와 같은 작업의 다양성을 위한 인스턴스
- Balance between:
- Compute (연산)
- Memory (메모리)
- Networking (네트워크)
- In the course, we will be using the t2.micro which is a General Purpose EC2 instance ⇒ (해당 강의에서는 t2.micro 사용 예정)
- Compute Optimized
- Great for compute-intensive tasks that require high performance processors (고성능 처리 연산을 위한 인스턴스)
- Batch processing workloads (배치 프로세싱)
- Media transcoding (영상 트랜스코딩)
- High performance web servers (고성능 웹서버)
- High performance computing (HPC) (고성능 연산)
- Scientific modeling & machine learning (머신러닝)
- Dedicated gaming servers (게임서버에 포커스가 맞춰짐)
- Great for compute-intensive tasks that require high performance processors (고성능 처리 연산을 위한 인스턴스)
- Memory Optimized
- Fast performance for workloads that process large data sets in memory ⇒ In memory 상에서의 대용량 데이터셋을 고속의 성능처리하도록 하기위해 사용
- Use cases:
- High performance, relational/non-relational databases (RDB/NoRDB의 고성능)
- Distributed web scale cache stores (분산된 웹 캐시 스토어)
- In-memory databases optimized for BI (business intelligence) (BI 최적화된 In-memory 데이터베이스)
- Applications performing real-time processing of big unstructured data (대용량의 비정형화 데이터의 실시간 처리)
- Storage Optimized
- Great for storage-intensive tasks that require high, sequential read and write access to large data sets on local storage ⇒ local storage에서의 대용량 데이터에 대한 고성능 sequential한 read write와 같은, storage 목적용 task를 위함
- Use cases:
- High frequency online transaction processing (OLTP) systems (OLTP 시스템)
- Relational & NoSQL databases
- Cache for in-memory databases (for example, Redis)
- Data warehousing applications
- Distributed file systems
Great website: https://instances.vantage.sh
- General Purpose
6. Introduction to Security Groups
- Security Groups are the fundamental of network security in AWS ⇒ Security Group은 AWS에서 네트워크 보안에 있어 기초가 되는 파트이다
They control how traffic is allowed into or out of our EC2 Instances ⇒ EC2 Instance에 대한 Inbound와 Outbound 규칙을 설정
- Security groups only contain allow rules ⇒ Security groups은 오직 allow rules만 포함한다
Security groups rules can reference by IP or by security group
⇒ Security group 규칙은 IP나 security group을 참고할 수 있다.
7. Security Groups Deeper Dive
- Security groups are acting as a “firewall” on EC2 instances
- They regulate:
- Access to Ports (포트 접근)
- Authorised IP ranges – IPv4 and IPv6 (IPv4와 IPv6에 대한 IP범위 인증)
- Control of inbound network (from other to the instance) (인바운드 규칙)
- Control of outbound network (from the instance to other) (아웃바운드 규칙)
8. Security Groups 알아두면 좋을 것들
- Can be attached to multiple instances ⇒ 다수 인스턴스에 적용 가능
Locked down to a region / VPC combination
⇒ region 및 VPC에 의존한다
- Does live “outside” the EC2 – if traffic is blocked the EC2 instance won’t see it ⇒ EC2 바깥에서 작동 중. 즉, 트래픽이 막힌다면, EC2 인스턴스는 볼 수가 없다
- It’s good to maintain one separate security group for SSH access ⇒ SSH 접근에 대한 하나의 security group 지속에 좋다
- If your application is not accessible (time out), then it’s a security group issue ⇒ 만약, application이 접근이 불가하다면, 이는 security group 이슈이다
- If your application gives a “connection refused“ error, then it’s an application error or it’s not launched ⇒ 만약 application이 “connection refused”에러를 낸다면, 이는 application 에러이거나 또는 app자체가 작동을 안한 것일수 있다
All inbound traffic is blocked by default
⇒ Inbound 트래픽은 보통 block상태가 default상태이다.
- All outbound traffic is authorised by default ⇒ Outbound 트래픽은 보통 모두 허용상태가 default로 되어있다.
9. Referencing other security groups Diagram
10. Classic Ports to know
- 22 = SSH (Secure Shell) - log into a Linux instance
- 21 = FTP (File Transfer Protocol) – upload files into a file share
- 22 = SFTP (Secure File Transfer Protocol) – upload files using SSH
- 80 = HTTP – access unsecured websites
- 443 = HTTPS – access secured websites
- 3389 = RDP (Remote Desktop Protocol) – log into a Windows instance
11. EC2 인스턴스 구매 방식
1) On-Demand Instance (온디맨드)
- Pay for what you use
- Linux 또는 Windows : 첫 1분이 지난 후, 초당 청구비용 발생
- 다른 OS : 시간당 청구비용 발생
- 가장 높은 비용이 예상되나 선불결제가 아니므로 언제든 사용 가능
- No long-term commitment : 단기적으로 사용할 때 목적으로 나음
Recommended for short-term and un-interrupted workloads, where you can’t predict how the application will behave
⇒ 어플리케이션 작동방식을 예측할 수 없는 연속적인 단기 워크로드에 적합
2) Reserved (1 & 3 years) (예약)
- Reserved Instance (예약 인스턴스)
- 단순 예약 인스턴스로 데이터베이스 같은 장기 workload에 사용
- On-demand에 비해 약 72% 비용 절약 가능
- 1년 또는 3년 중에서 선택 가능하며, 3년 기간시 할인율이 더 큼
- 선 결제를 원하지 않을 경우 매달 비용 지불
- 부분 또는 전체 선결제도 가능한데, 전체 선결제일때는 서버 비용을 바로 당일 결제
- 특정 인스턴스 타입을 예약
- 애플리케이션이 안정된 상태로 사용되는 데이터베이스 등에 추천. 3년간 데이터 베이스를 사용해야하는 경우라면 큰 비용 절감 가능
- Convertible Reserved Instances (전환형 예약 인스턴스)
- 시간이 지난 후 다른 종류의 인스턴스 변경 가능
- 인스턴스 유형을 바꿀 수 있어 할인율은 줄어 약 66% 할인
3) Saving Plans (1 & 3 years) (세이빙 플랜)
Get a discount based on long-term usage (up to 72% - same as RIs)
⇒ 장시간 사용을 베이스로 한 할인을 받음
Commit to a certain type of usage ($10/hour for 1 or 3 years)
⇒ 특정 유형 사용에 따른 기여 (1년 또는 3년 내에서 시간당 $10)
Usage beyond EC2 Savings Plans is billed at the On-Demand price
⇒ EC2 Saving Plans을 넘어선 사용은 On-demapnd 요금에서 청구된다
Locked to a specific instance family & AWS region (e.g., M5 in us-east-1)
⇒ 특정 family와 AWS region에 귀속된다
Flexible across:
- Instance Size (e.g., m5.xlarge, m5.2xlarge) : 인스턴스 사이즈
- OS (e.g., Linux, Windows) : 운영체제
- Tenancy (Host, Dedicated, Default)
4) Spot Instances (스팟 인스턴스)
- AWS에서 할인율이 가장 높은 옵션 (On-Demand와 비교하면 최대 90%까지 할인)
- 사용 안하는 인스턴스를 경매 방식으로 구매하여 사용하는 옵션으로 AWS 클라우드의 미사용 용량을 활용
- 지불하고자 하는 가격이 현재 스팟 인스턴스 가격보다 낮다면 인스턴스가 언제든 중단
- 저렴한 단기 workload용 인스턴스
- 손실 가능성이 있으며 신뢰성 낮음
- 단발성 데이터 분석인 배치 로드
- 이미지 프로세싱
- 분산 워크로드
- 데이터베이스나 중요한 Job들은 절대 사용하지 말 것
5) Dedicated Hosts (전용 호스트)
- 물리적 서버 전체를 예약하고 인스턴스 배치를 제어
- EC2 인스턴스를 갖춘 유저 중심의 물리적 서버 (하나의 서버 전체를 임대하는 형식)
- 전용 호스트를 사용하면 준수 요건의 처리가 쉽다
- 기존 서버 결합 소프트웨어 라이선스의 사용이 가능하기 때문에 비용 절감 가능
- 3년의 예약 기간 동안 계정에 할당 → 이런 계약 사항을 이행해야만 하고 저네 서버를 독자적으로 사용하기 때문에 비용이 상승
- 만약 복잡한 라이선스 모델의 소프트웨어를 사용하거나 자가 라이센스를 가진 경우, 또는 강력한 규제나 규정 준수 요건이 있을 때 상당히 도움을 주는 옵션
- 다른 AWS 고객들은 서버를 사용할 수 없고 본인만 사용
6) Dedicated Instance (전용 인스턴스)
- 단일 고객 전용 하드웨어의 VPC (Virtual Private Cloud)에서 실행되는 Amazon EC2 인스턴스
- 사용자 전용 하드웨어에서 실행되는 EC2 인스턴스
- 같은 계정의 다른 인스턴스와 하드웨어를 공유하며 인스턴스가 어떻게 배치될지에 대해서는 간섭 안됨. 전용 하드웨어가 있어도 해당 하드웨어의 근본에는 접근 불가. 전용 호스트의 약한 버전.
- 전용 호스트 vs 전용 인스턴스
- 두 옵션 모두 전용 물리적 서버 사용
- 전용 호스트는 호스트당 청구, 전용 인스턴스는 인스턴스 당 청구
- 전용 호스트는 하드웨어의 근본에 접근 권한을 많이 제공하므로 전용호스트에서 사용 가능한 다양한 서버 결합 라이센스를 받을 수 있음
- 전용 인스턴스 자동 인스턴스 배치
- 전용 호스트가 관여도가 더 높으므로 서버 결합 라이센스가 있는 경우 적합할 것이고, 전용 인스턴스의 경우 높은 수준의 규제 준수가 필요해 하드웨어를 타인과 공유하고자 하지 않을 때 적합
7) EC2 Capacity Reservations (EC2 용량 예약)
Reserve On-Demand instances capacity in a specific AZ for any duration
⇒ 어떠한 기한에 상관없이 특정한 AZ에 있어 On-Demand 용량을 예약
You always have access to EC2 capacity when you need it
⇒ 필요할때마다 EC2 용량에 접근 가능
No time commitment (create/cancel anytime), no billing discounts
⇒ 시간에 얽매이지 않음. 언제든 생성/취소 가능. 요금 할인 없음
Combine with Regional Reserved Instances and Savings Plans to benefit from billing discounts
⇒ region 예약 인스턴스와 Saving plnas 조합은 요금 할인으로부터 이점이 있다
You’re charged at On-Demand rate whether you run instances or not
⇒ 인스턴스를 돌릴때나 아닐때나 on-demand 효율에 따라 비용 청구됨
Suitable for short-term, uninterrupted workloads that needs to be in a specific AZ
⇒ 저렴한 단기 workload용 인스턴스에 적합
8. 올바른 인스턴스를 구매하는 방법 (호텔을 통한 예시)
- On-demand : 언제든 원할때 원래 가격을 내고 호텔에 묵을 수 있음
- Reserved Instance : 오랜 기간 호텔에 머무는 것으로 미리 계획을 세움. 길게 머물기 때문에 할인도 가능
- Saving Plans : 일정 기간동안, 시간당 총 금액을 지불하고 아무 룸에 묵는다
- Spot Instance : 밤에 객실이 빌 때 파격적인 할인을 선보여 객실을 비워둘 때의 손해를 만회하려고하는데, 내가 내는 객실비보다 더 많이 지불할 손님을 찾게되면 쫓아낼 수 있음
- Dedicated Host : 호텔 전체를 혼자서 예약
- Capacity Reservations : 묵지 않는다 하더래도, 총 금액을 지불하고 나서 특정기간동안 룸 하나를 예약한다
9. EC2 Spot Instance Requests
Can get a discount of up to 90% compared to On-demand
⇒ 온디맨드와 비교해서 최대 90% 할인을 받는것이 가능
- Define max spot price and get the instance while current spot price < max ⇒ spot 가격 최대치를 정하고, 현재 spot 가격이 최대치 미만인 동안에는 instance 획득 가능
- The hourly spot price varies based on offer and capacity ⇒ 시간당 spot price는 제공과 capacity에 기반을 두고 있다
If the current spot price > your max price, you can choose to stop or terminate your instance with a 2 minutes grace period.
⇒ 만약 현재 spot price가 max price보다 높다면, 2분안에 인스턴스를 stop 또는 terminate 중 선택 가능하다
- Other strategy: Spot Block (Spot 블록)
- “block” spot instance during a specified time frame (1 to 6 hours) without interruptions ⇒ “block” 스팟 인스턴스는 interruption없는 특정 시간대(1시간에서 6시간) 동안 존재
In rare situations, the instance may be reclaimed
⇒ 드문 경우로, 인스턴스가 재활용될수 있음
Used for batch jobs, data analysis, or workloads that are resilient to failures.
⇒ 배치 잡, 데이터 분석, 실패에도 탄력적인 workload에 사용
Not great for critical jobs or databases
⇒ 중요한 job이나 또는 데이터베이스에는 맞지 않음
Spot Block은 새 AWS 고객에게 있어 2021년 7월 1일부터 더 이상 작동하지 않고, 2022년 12/31 이후로는 지원 종료. (그러나 아마 시험에서는 나올 확률이 높기에 슬라이드 삭제는 안함)
(시험에 나올 확률 높음)
You can only cancel Spot Instance requests that are open, active, or disabled.
⇒ Spot 인스턴스에 대한 취소 요청으로는 open, active, disable이 존재
Cancelling a Spot Request does not terminate instances
⇒ Spot 인스턴스 취소가 인스턴스 terminate를 하지는 않음
You must first cancel a Spot Request, and then terminate the associated Spot Instances
⇒ Spot Request를 먼저 취소한 후, 연관된 Spot 인스턴스를 terminate해야한다
10. Spot Fleets
Spot Fleets = set of Spot Instances + (optional) On-Demand Instances
⇒ Spot 인스턴스 모음 + (선택) 온디맨드 인스턴스
- The Spot Fleet will try to meet the target capacity with price constraints ⇒ Spot Fleet은 가격 제한이 있는 target capacity를 맞닥뜨릴 것이다
Define possible launch pools: instance type (m5.large), OS, Availability Zone
⇒ launch pool 설정 가능 : 인스턴스 타입, OS, 사용 가능 영역
Can have multiple launch pools, so that the fleet can choose
⇒ 다수 launch pool를 가질 수 있음. 그러므로 fleet은 원하는 것을 선택 가능
Spot Fleet stops launching instances when reaching capacity or max cost
⇒ Spot Fleet은 용량한계나 가격한계에 다다르면 인스턴스 launch를 멈춘다
- Strategies to allocate Spot Instances (Spot 인스턴스 할당 전략)
- lowestPrice: from the pool with the lowest price (cost optimization, short workload)
- diversified: distributed across all pools (great for availability, long workloads)
- capacityOptimized: pool with the optimal capacity for the number of instances
- priceCapacityOptimized (recommended): pools with highest capacity available, then select the pool with the lowest price (best choice for most workloads)
Spot Fleets allow us to automatically request Spot Instances with the lowest price
⇒ Spot Fleet은 저비용의 Spot 인스턴스 자동 요청을 허용하도록 되어있다
Spot Request 항목 : “Price Capacity Optimized”라 불리는 새로운 옵션이 존재. 즉 저비용과 용량 양쪽에 대한 최적화를 지원