Amazon EC2
- EC2 is one of the most popular of AWS' offering (EC2 = 탄력적 컴퓨팅 클라우드 = 서비스형 인프라)
- EC2 = Elastic Compute Cloud = Infrastructure as a Service (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) (오토 스케일링 그룹을 사용한 서비스 확장)
- Knowing EC2 is fundamental to understand how the Cloud works
EC2 sizing & configuration options (EC2 크기 및 구성 옵션)
- Operating System (OS): Linux, Windows or Mac OS
- 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 (네트워크 카드: 카드 속도, 퍼블릭 IP 주소)
- Firewall rules: security group (방화벽 규칙: 보안 그룹)
- Bootstrap script (configure as first launch): EC2 User Data (부트스트랩 스크립트, 최초 실행 시 구성)
EC2 User Data
- It is possible to bootstrap our instance using an EC2 User data script (EC2 사용자 데이터 스크립트를 사용하여 인스턴스 부트스트랩 가능)
- bootstrapping means launching commands when a machine starts (부트스트래핑은 머신 시작 시 명령 실행을 의미)
- That script is only run once at the instance first start (스크립트는 인스턴스 최초 시작 시 한 번만 실행)
- EC2 user data is used to automate boot tasks such as: (EC2 사용자 데이터는 부팅 작업 자동화에 사용)
- 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 사용자 데이터 스크립트는 루트 사용자 권한으로 실행)
EC2 Instance Types - Overview
- You can use different types of EC2 instances that are optimised for different use cases (다양한 사용 사례에 최적화된 여러 유형의 EC2 인스턴스 사용 가능)
- 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 (인스턴스 클래스 내 크기)
(1) General Purpose
(2) Compute Optimized
(3) Memory Optimized
(4) Accelerated Computing
(5) Storage Optimized
(6) HPC Optimized
(7) Instance Feature
(8) Measuring Instance Performance
(1) EC2 Instance Types - General Purpose
- Great for a diversity of workloads such as web servers or code repositories (웹 서버 또는 코드 리포지토리와 같은 다양한 워크로드에 적합)
- Balance between :
- Compute
- Memory
- Networking
- In the course, we will be using the t2.micro which is a General Purpose EC2 instance
- General purpose instances provide a balance of compute, memory and networking resources, and can be used for a variety of diverse workloads. These instances are ideal for applications that use these resources in equal proportions such as web servers and code repositories. (범용 인스턴스는 컴퓨팅, 메모리, 네트워킹 리소스의 균형을 제공하며 다양한 워크로드에 사용 가능. 웹 서버 및 코드 리포지토리와 같이 이러한 리소스를 동등한 비율로 사용하는 애플리케이션에 이상적)
(2) EC2 Instance Types - 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 (전용 게임 서버)
- Compute Optimized instances are ideal for compute bound applications that benefit from high performance processor, Instance belonging to this family are well suited for batch processing workloads, media transcoding, high performance web servers, high performance computing (HPC), scientific modeling, dedicated gaming servers and ad server engines, machine learning inference and other compute intensive applications. (컴퓨팅 최적화 인스턴스는 고성능 프로세서의 이점을 활용하는 컴퓨팅 바운드 애플리케이션에 이상적. 배치 처리, 미디어 트랜스코딩, 고성능 웹 서버, HPC, 과학 모델링, 게임 서버, 광고 서버 엔진, 머신러닝 추론 및 기타 컴퓨팅 집약적 애플리케이션에 적합)
(3) EC2 Instance Types - Memory Optimized
- Fast performance for workloads that process large data sets in memory (메모리에서 대용량 데이터 세트를 처리하는 워크로드를 위한 빠른 성능)
- Use cases:
- High performance, relational/non-relational databases (고성능 관계형/비관계형 데이터베이스)
- Distributed web scale cache stores (분산 웹 규모 캐시 저장소)
- In-memory databases optimized for BI (business intelligence) (비즈니스 인텔리전스에 최적화된 인메모리 데이터베이스)
- Applications performing real-time processing of big unstructured data (대용량 비정형 데이터의 실시간 처리를 수행하는 애플리케이션)
(5) EC2 Instance Types - Storage Optimized
Great for storage-intensive tasks that require high, sequential read and write access to large data sets on local storage (로컬 스토리지의 대용량 데이터 세트에 대한 높은 순차적 읽기 및 쓰기 액세스가 필요한 스토리지 집약적 작업에 적합)
-
Use cases:
- High frequency online transaction processing (OLTP) systems (고빈도 온라인 트랜잭션 처리 시스템)
- Relational & NoSQL databases (관계형 및 NoSQL 데이터베이스)
- Cache for in-memory databases (for example, Redis) (인메모리 데이터베이스용 캐시, 예: Redis)
- Data warehousing applications (데이터 웨어하우스 애플리케이션)
- Distributed file system (분산 파일 시스템)
EC2 Instance Types : example
Introduction to Security Groups (보안그룹)
- Security Groups are the fundamental of network security in AWS (보안 그룹은 AWS 네트워크 보안의 기본)
- They Control how traffic is allowed into or out of our EC2 Instances. (EC2 인스턴스로 들어오거나 나가는 트래픽 제어)
- Security groups only contain allow rules (보안 그룹은 허용 규칙만 포함)
- Security groups rules can reference by IP or by security group (보안 그룹 규칙은 IP 또는 보안 그룹으로 참조 가능)
Security Groups Deeper Dive
- Security groups are acting as a "firewall" on EC2 instances (보안 그룹은 EC2 인스턴스의 "방화벽" 역할)
- They regulate: (규제 항목)
- Access to Ports (포트 액세스)
- Authorised IP ranges - IPv4 and IPv6 (승인된 IP 범위 - IPv4 및 IPv6)
- Control of inbound network (from other to the instance) (인바운드 네트워크 제어, 외부에서 인스턴스로)
- Control of outbound network (from the instance to other) (아웃바운드 네트워크 제어, 인스턴스에서 외부로)
Security Groups Deeper Dive
- Can be attached to multiple instances (보안그룹은 여러 인스턴스에 연결 가능)
- Locked down to a region/VPC combination (리전/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 액세스를 위한 별도의 보안 그룹 유지 권장)
- If your application is not accessible (time out), then it's a security group issue (애플리케이션 액세스 불가(타임아웃) 시 보안 그룹 문제)
- If your application gives a "connection refused" error; then it's an application error or it's not launched (애플리케이션이 "연결 거부" 오류를 주면 애플리케이션 오류 또는 미실행 상태)
- All inbound traffic is blocked by default (모든 인바운드 트래픽은 기본적으로 차단)
- All outbound traffic is authorised by default (모든 아웃바운드 트래픽은 기본적으로 허용)
Referencing other security groups Diagram
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
SSH Summary Table
1. How to SSH into your EC2 Instance Linux/Mac OS X ?
- SSH is one of the most important function. It allows you to control a remote machine, all using the command line. (SSH는 가장 중요한 기능 중 하나로 명령줄을 사용하여 원격 머신을 제어 가능)
2. How to SSH into your EC2 Instance Windows ?
- We'll learn how to SSH into your EC2 instance using Windows
- SSH is one of the most important function. It allows you to control a remote machine, all using the command line. (SSH는 명령줄을 사용하여 원격 머신을 제어하는 중요한 기능)
- We will configure all the required parameters necessary for doing SSH on Windows using the free tool Putty. (무료 도구 Putty를 사용하여 Windows에서 SSH에 필요한 모든 매개변수 구성)
SSH Troubleshooting
(1) There's a connection timeout (연결 타임아웃 발생 시)
This is a security group issue. Any timeout (not just for SSH) is related to security groups or a firewall. Ensure your security group looks like this and correctly assigned to your EC2 instance. (보안 그룹 문제. 모든 타임아웃은 보안 그룹 또는 방화벽과 관련. 보안 그룹이 올바르게 구성되고 EC2 인스턴스에 할당되었는지 확인)
(2) There's still a connection timeout issue (여전히 연결 타임아웃 발생)
If your security group is properly configured as above, and you still have connection timeout issues, then that means a corporate firewall or a personal firewall is blocking the connection. Please use EC2 Instance Connect as described in the next lecture. (보안 그룹이 올바르게 구성되었는데도 타임아웃이 발생하면 회사 방화벽 또는 개인 방화벽이 연결을 차단하는 것. EC2 Instance Connect 사용 권장)
(3) SSH does not work on Windows (Windows에서 SSH 작동 안 함)
If it says: ssh command not found, that means you have to use Putty (ssh 명령을 찾을 수 없다고 표시되면 Putty 사용 필요)
Follow again the video. If things don't work, please use EC2 Instance Connect as described in the next lecture (작동하지 않으면 EC2 Instance Connect 사용)
(4) There's a connection refused (연결 거부)
This means the instance is reachable, but no SSH utility is running on the instance (인스턴스에 접근 가능하지만 SSH 유틸리티가 실행되지 않는 상태)
Try to restart the instance (인스턴스 재시작 시도)
If it doesn't work, terminate the instance and create a new one. Make sure you're using Amazon Linux 2 (작동하지 않으면 인스턴스 종료 후 새로 생성. Amazon Linux 2 사용 확인)
(5) Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
This means either two things: (권한거부의 두가지 원인)
You are using the wrong security key or not using a security key. Please look at your EC2 instance configuration to make sure you have assigned the correct key to it. (잘못된 사용자. Amazon Linux 2에서는 ec2-user 사용 확인)
You are using the wrong user. Make sure you have started an Amazon Linux 2 EC2 instance, and make sure you're using the user ec2-user. This is something you specify when doing ec2-user@ (ex: ec2-user@35.180.242.162) in your SSH command or your Putty configuration
(6) I was able to connect yesterday, but today I can't (어제는 연결되었는데 오늘은 안 됨)
This is probably because you have stopped your EC2 instance and then started it again today. When you do so, the public IP of your EC2 instance will change. Therefore, in your command, or Putty configuration, please make sure to edit and save the new public IP.
(EC2 인스턴스를 중지했다가 다시 시작하면 퍼블릭 IP가 변경됨. 명령 또는 Putty 구성에서 새 퍼블릭 IP로 수정 필요)
EC2 Instances Purchasing Options
- (1) On-Demand Instances - short workload, predictable pricing, pay by second (온디맨드 인스턴스 : 단기 워크로드, 예측 가능한 가격, 초당 과금)
-
(2) Reserved (1 & 3 years)
- Reserved Instances - long workloads (예약 인스턴스 : 장기 워크로드, 유연한 인스턴스)
- Convertible Reserved Instances - long workloads with flexible instances
- (3) Saving Plans (1 & 3 years) - commitment to an amount of usage, long workload (절감 플랜 : 사용량 약정, 장기 워크로드)
- (4) Spot Instances - short workloads, cheap, can lose instances (less reliable) (스팟 인스턴스 : 단기 워크로드, 저렴, 인스턴스 손실 가능, 신뢰성 낮음)
- (5) Dedicated Hosts - book an entire physical server, control instance placement (전용 호스트 : 전체 물리 서버 예약, 인스턴스 배치 제어)
- (6) Dedicated Instance - no other customers will share your hardware (전용 인스턴스 : 다른 고객과 하드웨어 공유 안 함)
- (7) Capacity Reservations - reserve capacity in a specific AZ for any duration (용량 예약 : 특정 AZ에서 원하는 기간 동안 용량 예약)
(1) EC2 On Demand
- Pay for what you use:
- Linux or Windows - billing per second, after the first minute
- All other operation systems - billing per hour
- Has the highest cost but no upfront payment
- No long-term commitment
- Recommended for short-term and un-interrupted workloads, where you can't predict how the application will behave.
(온디맨드 : 사용한만큼 지물, Linux 또는 Windows - 첫 1분 이후 초당 과금, 기타 운영체제 - 시간당 과금. 가장 높은 비용이지만 선불 없음, 장기약정 없음, 애플리케이션 동작을 예측할 수 없는 단기 무중단 워크로드에 권장)
(2) EC2 Reserved Instances
- Up to 72% discount compared to On-demand
- You reserve a specific instance attributes (Instance Type, Region, Tenancy, OS)
- Reservation Period - 1year (+discount) or 3years (+++discount)
- Payment Options - No Upfront(+), Partial Upfront(++), All Upfront(+++)
- Reserved Instance's Scope - Regional or Zonal (reserve capacity in an AZ)
- Recommended for steady-state usage application (think database)
- You can buy and sell in the Reserved Instance Marketplace
(예약 인스턴스 : 온디맨드 대비 최대 72% 할인, 특정 인스턴스 속성 예약: 인스턴스 타입, 리전, 테넌시, OS / 지불옵션 : 선불 없음, 부분 선불, 전체 선불 / 리전 또는 영역, AZ 용량 예약 / 안정적인 사용량 애플리케이션에 권장, 예: 데이터베이스, 예약 인스턴스 마켓플레이스에서 구매 및 판매 가능)
-
Convertible Reserved Instance
- Can change the EC2 instance type, instance family, OS, scope and tenancy
- Up to 66% discount (전환 가능 예약 인스턴스 : EC2 인스턴스 타입, 패밀리, OS, 범위, 테넌시 변경 가능, 최대 66% 할인)
(3) EC2 Saving Plans
- 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)
- Usage beyond EC2 Savings Plans is billed at the On-Demand price
- Locked to a specific instance family & AWS region (e.g., M5 in us-east-1)
- Flexible across:
- Instance Size (e.g., m5.xlarge, m5.2xlarge)
- OS (e.g., Linux, Windows)
- Tenancy (Host, Dedicated, Default)
(절감 플랜 : 장기 사용 기반 할인, 최대 72%, RI(예약 인스턴스, Reserved Instances)와 동일, 특정 사용량 약정, 시간당 $10, 1년 또는 3년, 절감 플랜 초과 사용은 온디맨드 가격으로 청구, 특정 인스턴스 패밀리 및 AWS 리전에 고정, 유연성 : 인스턴스 크기, 운영체제, 테넌시)
(4) EC2 Spot Instances
- Can get a discount of up to 90% compared to On-demand
- Instances that you can "lose" at any point of time if your max price is less than the current spot price
- the MOST cost-efficient instances in AWS
- Useful for workloads that are resilient to failure
- Batch jobs
- Data analysis
- Image processing
- Any distributed workloads
- Workloads with a flexible start and end time
- Not suitable for critical jobs or databases
(스팟 인스턴스 : 온디맨드 대비 최대 90% 할인, 최대 가격이 현재 스팟 가격보다 낮으면 언제든지 인스턴스 손실 가능, AWS에서 가장 비용 효율적인 인스턴스, 장애에 탄력적인 워크로드에 유용 : 배치 작업, 데이터 분석, 이미지 처리, 분산 워크로드, 유연한 시작 및 종료 시간 / 중요한 작업 또는 데이터베이스에는 부적합)
(5) EC2 Dedicated Hosts
- A physical server with EC2 instance capacity fully dedicated to your use
- Allows you address compliance requirements and use your existing server-bound software licenses (per-socket, per-core, pe-VM software licenses)
- Purchasing Options:
- On-demand - pay per second for active Dedicated Host
- Reserved - 1 or 3 years (No Upfront, Partial Upfront, All Upfront)
- The most expensive option
- Useful for software that have complicated licensing model (BYOL - Bring Your Own License)
- Or for companies that have strong regulatory or compliance needs
(전용 호스트 : 사용자 전용 EC2 인스턴스 용량을 가진 물리 서버, 규정 준수 요구사항 충족 및 기존 서버 종속 소프트웨어 라이선스 사용 가능, 소켓당/코어당/VM당 / 온디맨드 - 활성 전용 호스트에 대해 초당 과금 / 가장 비싼 옵션, 복잡한 라이선스 모델을 가진 소프트웨어에 유용, BYOL, 강력한 규제 또는 규정 준수 요구사항이 있는 기업용)
(6) EC2 Dedicated Instance
- Instances run on hardware that's dedicated to you
- May share hardware with other instances in same account
- No control over instance placement (can move hardware after Stop/Start)
(전용 인스턴스 : 사용자 전용 하드웨어에서 실행되는 인스턴스, 동일 계정 내 다른 인스턴스와 하드웨어 공유 가능, 인스턴스 배치 제어 불가, 중지/시작 시 하드웨어 이동 가능)
(7) EC2 Capacity Reservation
- Reserve On-Demand instances capacity in a specific AZ for any duration
- You always have access to EC2 capacity when you need it
- No time commitment (create/cancel anytime), no billing discounts
- Combine with Regional Reserved Instances and Savings Plans to benefit form billing discounts
- You're charged at On-Demand rate whether you run instances or not
- Suitable for short-term, uninterrupted workloads that needs to be in a specific AZ
(용량 예약 : 특정 AZ에서 온디맨드 인스턴스 용량을 원하는 기간만큼 예약, 필요할 때 언제든 EC2 용량 사용 가능, 기간 약정 없음, 언제든 생성/취소 가능, 요금 할인 없음, Regional RI 및 Savings Plans와 결합하여 요금 할인 혜택, 인스턴스 실행 여부와 관계없이 온디맨드 요금 청구, 특정 AZ에서 실행해야 하는 단기 무중단 워크로드에 적합)
EC2 Spot Instance Requests
- Can get a discount of up to 90% compared to On-demand
- Define max spot price and get the instance while current spot price < max
- The hourly spot price varies based on offer and capacity
- If the current spot price > your max price you can choose to stop or terminate your instance with a 2minutes grace period.
-
Other strategy: Spot Block
- "block" spot instance during a specified time frame (1 to 6 hours) without interruptions
- In rare situations, the instance may be reclaimed
Used for batch jobs, data analysis, or workloads that are resilient to failures
Not great for critical job or databases
(EC2 스팟 인스턴스 요청 : 온디맨드 대비 최대 90% 할인, 최대 스팟 가격 정의, 현재 스팟 가격 < 최대 가격일 때 인스턴스 획득, 시간당 스팟 가격은 공급 및 용량에 따라 변동, 현재 스팟 가격 > 최대 가격일 경우 2분 유예 기간 후 인스턴스 중지 또는 종료 선택 / 기타 전략: 스팟 블록 : 지정된 시간 동안 중단 없이 스팟 인스턴스 확보, 1~6시간, 드물게 인스턴스가 회수될 수 있음 / 배치 작업, 데이터 분석 또는 장애에 탄력적인 워크로드에 사용, 중요한 작업 또는 데이터베이스에는 부적합)
How do you terminate a spot instance?
With Spot Request, we are defining how many instances we want, your maximum price you're going to pay, the launch specification, so the AMI and so on, and when our request is valid from and until (but it can be infinite)
There's two types of requests. (1) One-time request for spot instances. (2) Persistent request for spot instances.
(1) One-time request for spot instances : As soon as your spot request is fulfilled, your instances are going to be launched, and then your spot request will go away because it was a one-time request type.
(2) Persistent request for spot instances : we want this number of instances to be valid as long as the spot request is valid from to valid until. if somehow our instances do get stopped or interrupted based on the spot price, then your spot request will go back into action. (In spot instance mode, if your spot instances is still active, our spot request automatically will be smart enough to restart a launch)
스팟 인스턴스 요청 : 원하는 인스턴스 수 및 최대 비용을 정의
요청 유형
(1) 스팟 인스턴스에 대한 단일 요청 (one-time)
(2) 스팟 인스턴스에 대한 지속적인 요청 (persistent)
스팟 인스턴스에 대한 단일 요청일 경우, 스팟 요청이 수행되자마자 인스턴스가 실행되고, 스팟 요청은 사라짐 (단일 요청 유형이므로)
반면 스팟 인스턴스에 대한 지속적인 요청일 경우, 스팟 요청이 유효할 때 까지, 스팟 인스턴스의 수는 유효함. 만약 스팟 인스턴스가 스팟 가격에 의해 멈추거나 방해받으면 다시 스팟요청을 함으로써 여전히 active한 상태 유지함.
You can only cancel Spot Instance request that are open, active, or disabled.
Cancelling a Spot Request does not terminate instances
You must first cancel a Spot Request, and then terminate the associated Spot Instances.
(open, active 또는 disabled 상태의 스팟 인스턴스 요청만 취소 가능, 스팟 요청 취소가 인스턴스를 종료하지는 않음, 먼저 스팟 요청을 취소한 다음 연결된 스팟 인스턴스를 종료해야 함)
Spot Fleets
- Ultimate way to save money
- Spot Fleets = set of Spot Instances + (optional) On-Demand Instances
-
The Spot Fleet will try to meet the target capacity with price constraints
- Define possible launch pools: instance type (m5.large), OS, Availability Zone
- Can have multiple launch pools, so that the fleet can choose
- Spot Fleet stops launching instances when reaching capacity or max cost
-
Strategies to allocate Spot Instances:
- 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
스팟 플릿 = 스팟 인스턴스 집합 + 선택적 온디맨드 인스턴스
스팟 플릿은 가격 제약 조건 내에서 목표 용량을 충족하려고 시도, 가능한 시작 풀 정의: 인스턴스 타입, OS, 가용 영역, 여러 시작 풀을 가질 수 있어 플릿이 선택 가능, 용량 또는 최대 비용 도달 시 인스턴스 시작 중지스팟 인스턴스 할당 전략
가장 낮은 가격의 풀에서 선택, 비용 최적화, 단기 워크로드, 모든 풀에 분산, 가용성에 적합, 장기 워크로드, 인스턴스 수에 대한 최적 용량을 가진 풀, 사용 가능한 최고 용량 풀 중 가장 낮은 가격의 풀 선택, 대부분의 워크로드에 최선의 선택, 권장
스팟 플릿을 사용하면 가장 낮은 가격으로 스팟 인스턴스를 자동으로 요청 가능











Top comments (0)