[aws] Certified Solutions Architect Associate - EC2

Elastic Compute Cloud

Billing and Cost Management

ec2를 사용하기 전에 요금에 대해 알아보자.
요금은 Billing and Cost Management 페이지에서 확인할 수 있다.

  • Bills(청구서): 이번달 요금의 요약 정보, Charges by account, Charges by services(서비스 별 요금 세부사항)
  • free tier: 프리 티어 사용량을 확인할 수 있다.
  • Budgets(예산): Set custom budgets that alert you when you exceed your budgeted thresholds; 요금을 지정해서 알림이 보내도록 설정

위 그림은 Budget(예산)을 생성하는 페이지의 템플릿을 나타내고 있다. 프리티어에서 제공하는 한도에서 벗어나면 알림을 보내도록 설정할 수 있다.

EC2 configuration options

  • os
  • cpu
  • ram
  • storage; ebs, efs or ec2 instance store
  • network card
  • security group
  • Bootstrap script

EC2 User Data

  • bootstrap our instances using an EC2 User data script
  • 스크립트는 EC2 run에 한 번만 실행된다.
  • update, install software, etc
  • EC2 user data script runs with the root user; 따라서 모든 명령어는 sudo로 시작된다.

EC2 instance type

예를 들어 m5.2xlarge 로 ec2를 생성한다고 하면,
m의 instance class와 5번째 generation, size는 2xlarge로 선택한 것이다.

  • general purpose: m이나 t로 시작하는 클래스가 있고 compute, memory, network가 균형있게 할당된다.
  • compute optimized: high performance를 위한 클래스. 클래스가 c로 시작한다.
  • memory optimized: 관계형 데이터베이스에서 높은 성능을 보인다. r로 시작하는 클래스들이 있다.

EC2 security groups

  • fundamental of network security
  • control how traffic is allowed into ec2
  • only contain allow rules
  • can reference by IP or by other security group
  • ec2 외부의 firewall이라고 이해하자.

more details

  • can be attached to multiple instances
  • locked down to a region / VPC combination; 리전과 vpc에 속하는 개념이기 때문에 리전을 옮기거나 다른 vpc의 자원에서 사용하기 위해서는 새로 보안 정책을 만들어야 한다.
  • ssh access에 대해 보안 정책을 분리해서 관리하는 것이 좋다.
  • 만약 time out으로 접근할 수 없다면 security group issue에 해당한다.(잊을 만하면 이 문제가 나타나곤 했다.)
  • connection refused라면 instance의 문제이거나 application 에러 일 수 있다.
  • inbound는 기본적으로 모든 traffic을 block 한다.
  • outbound traffic은 기본적으로 authorised이다.
  • "A" security group이 다른 보안 그룹 "B"를 포함한다면 별도의 설정 없이 B 그룹 내의 자원의 inbound traffic이 A 그룹의 자원으로 전송될 수 있다.

알아야 하는 port들

  • 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); ssh를 사용해서 파일을 전송하기 때문에 ssh와 포트 번호가 같다.
  • 80: http
  • 3389: rdp(remote desktop protocol); log into a windows

EC2 instance purchasing options

on-demand

  • short workload, predictable pricing, pay by second
  • linux or windows: billing per second
  • all other os: billing per hour
  • 짧은 기간이나 예측할 수 없는 프로젝트를 진행하고 있을 때 추천한다.

reserved

1 year or 3years

  • reserved instances: long workloads; 많은 할인을 받을 수 있다, on-demand와 비교했을 때 70프로 정도
  • convertible: long workloads with flexible; 인스턴스 유형을 중간에 변경하기를 원할 때(정확히는 instance family를 정한다. ex> m5)
  • payment option; 결제 방식으로는 no upfront, parial, all upfront(선결제)가 있다.
  • reserved 인스턴스 scope: regional or zonal;
  • Reserved Instance Marketplace에서 사고 팔 수 있다.
  • steady-state usage(일정한 사용량을 가진 애플리케이션에 권장)

savings plans

commitment to an amount of usage, long workload; 달러 단위로 사용량을 약정한다.

  • reserved와 비슷한 할인율을 받을 수 있다.
  • 1시간에 10달러까지의 상한선이 있으며, 이를 초과할 경우 on-demand price로 청구된다.
  • locked to a specific instance famil and region
  • flexible; instance size, os, tenancy

spot instances

very short workload and cheap(90%). but you can lose instance(less reliable); 인스턴스가 손실될 수 있음을 사전에 약속하기 때문에 신뢰할 수 없다. 내가 지정한 max price가 현재 가격보다 낮다면 인스턴스가 사라질 수 있다. 현재 가격은 매 시간 변경된다. 문제가 될 때, stop해서 다시 max price가 현재 가격보다 올라가면 인스턴스를 재개할 수 있다. 혹은 terminate해서 인스턴스를 종료할 수 있다. 2분의 유예 기간이 주어진다. spot block으로 일정시간 중단없이 실행하게 할 수 있다.

  • useful for
  • batch jobs, data analysis, image processing
  • or any distributed workload

not suitable for database

spot request

spot request(스팟 인스턴스 생성 요청)에는 인스턴스 수와 최대 가격, 사양, 요청의 유효 기간을 정할 수 있다. 요청은 one time, persistent의 두 유형이 있다. persistent에서는 어떤 이유에서든 인스턴스가 정해진 개수보다 작아지면 spot 인스턴스를 다시 시작해서 개수를 채운다. 따라서 spot instance를 중단하기 위해서는 persistent request를 종료하고 인스턴스를 종료해야 한다. request를 종료한다고 해서 실행되고 있는 instance가 종료되는 것은 아니다.

spot fleets

spot instance를 이용하여 비용을 줄이는 방법 중 하나. 목표 용량에 맞춰 스팟 인스턴스를 실행한다. on-demand 인스턴스를 포함할 수 있다.
target capacity with price constraint를 정한다. 인스턴스 유형과 os, az를 포함하는 launch pool를 설정하여 spot fleet이 풀을 통해 목표 용량을 맞춘다. 여기서 말하는 target capacity는 인스턴스 개수 혹은 vCPU, memory 크기 중 지정할 수 있다.

스팟 플릿을 사용하는 여러 전략이 있는데, lowestprice, diversified(높은 가용성, for long workload), capacityOptimized(with optimal capacity), priceCapacityOptimaized(pools with highest capacity available, then select the poll with the lowest price) 이 있다.

aws 공식 문서 참고

콘솔을 사용하여 스팟 인스턴스가 포함된 플릿을 생성하려는 경우 스팟 플릿 대신 Auto Scaling 그룹을 사용하는 것이 좋습니다.

dedicated host

dedicated(전용의)

book an entire physical server, control instance placement
결제 방법으로는 on-demand 방식과 reserved 방식이 있다. 다른 방식과 비교할 때 가장 비싸다. licensing model(Bring Your Own License) 혹은 강한 규제 속에서 운영할 때 적합하다.

dedicated instances

no other customers will share your hardware
host랑은 나만의 하드웨어를 갖는 것과, low level의 하드웨어에 대한 가시성을 가지고 물리 서버를 갖는 것의 차이를 갖는다.

capacity reservations

원하는 기간 동안 선택한 가용 영역에 용량을 선택할 수 있다. 인스턴스를 실행하지 않아도 비용은 청구된다. 정해진 용량에 대해서 on-demand로 부과된다고 이해했다.