AWS EC2 Spot 비용 확인하기
AWS EC2 Spot 인스턴스 비용 확인하기: 클라우드 비용 최적화의 첫걸음
AWS EC2 Spot 인스턴스는 고정적인 작업에는 적합하지 않을 수 있지만, 일정 유연성이 허용되는 워크로드에는 탁월한 비용 절감 효과를 제공합니다. 그러나 Spot 인스턴스를 활용하기 위해서는 현재 시장에서의 가격 동향을 파악하는 것이 중요합니다. 이 글에서는 AWS에서 Spot 인스턴스의 현재 비용을 확인하는 방법을 자세히 알아보고, 이를 통해 어떻게 클라우드 비용을 효율적으로 관리할 수 있는지 소개하겠습니다. Spot 비용을 실시간으로 모니터링하여 예산을 절약하고, 안정적으로 워크로드를 관리하는 데 도움을 드리겠습니다.
1. 사이트에서 확인하기

이미지와 같이 https://aws.amazon.com/ko/ec2/spot/pricing/ 해당 주소에 접속 해 지역(Region) 을 선택후 인스턴스 타입을 체크해서 시간당 요금을 확인한다.
장점 : 간단하게 확인 가능하다.
단점 : spot은 zone 별로 요금이 다르기 때문에 정확한 금액은 알 수 없다.
2. AWS 콘솔에서 확인하기
- https://console.aws.amazon.com/ec2/에서 Amazon EC2 콘솔을 엽니다.
- 탐색 창에서 스팟 요청을 선택합니다.
- 요금 내역을 선택합니다.
- 그래프에서 가용 영역 또는 인스턴스 유형별로 요금 내역을 비교하도록 선택합니다.다음 스크린샷은 여러 인스턴스 유형에 대한 요금 비교를 보여 줍니다.

-
- 가용 영역(Availability Zones)을 선택한 경우 인스턴스 유형(Instance type), 운영 체제(플랫폼(Platform)) 및 가격 기록을 볼 날짜 범위(Date range)를 선택합니다.
- 인스턴스 유형(Instance Types)을 선택한 경우 최대 5개의 인스턴스 유형(Instance type(s)), 가용 영역(Availability Zone), 운영 체제(플랫폼(Platform)) 및 가격 기록을 볼 날짜 범위(Date range)를 선택합니다.
- 그래프 위로 마우스를 가져가면(포인터 이동) 선택한 날짜 범위의 특정 시간의 가격이 표시됩니다. 요금은 그래프 위의 정보 블록에 표시됩니다. 맨 위 행에 표시된 요금은 특정 날짜의 요금을 보여줍니다. 두 번째 행에 표시된 요금은 선택한 날짜 범위의 평균 요금을 보여줍니다.
- vCPU당 요금을 표시하려면 정규화된 요금 표시를 켭니다. 인스턴스 유형에 대한 요금을 표시하려면 정규화된 가격 표시를 끕니다.
3. AWS CLI 를 통해 확인하기
- aws cli 확인하기
예시)
aws ec2 describe-spot-price-history \
--instance-types <인스턴스 타입> \
--product-description <운영 체제> \
--availability-zone <가용 영역>
필수 옵션
--instance-types
Spot 비용을 확인할 EC2 인스턴스 타입입니다. 예: t3.medium, m5.large 등.
--product-description
EC2 인스턴스에 설치된 운영 체제 및 소프트웨어에 대한 설명입니다. 주요 값: Linux/UNIX , Windows
--availability-zone
비용을 확인할 AWS 가용 영역입니다. 예: us-east-1a , ap-northeast-2a
활용)
aws ec2 describe-spot-price-history \
--instance-types t3.medium \
--product-description "Linux/UNIX" \
--availability-zone ap-northeast-2a

결과값을 보면 Timestamp의 시간에 따라 가격이 조금씩 변경된걸 확인 가능하다.
특정 시간을 확인해보려면 --start-time과 --end-time 지정한다.
aws ec2 describe-spot-price-history \
--instance-types t3.medium \
--product-description "Linux/UNIX" \
--availability-zone ap-northeast-2a \
--start-time 2024-11-11T00:00:00Z \
--end-time 2024-11-14T23:59:59Z

비용만 간단하게 확인하는 방법
aws ec2 describe-spot-price-history \
--instance-types t3.medium \
--product-description "Linux/UNIX" \
--availability-zone ap-northeast-2a \
--start-time 2024-11-11T00:00:00Z \
--end-time 2024-11-14T23:59:59Z \
--query 'SpotPriceHistory[*].[InstanceType, SpotPrice, Timestamp]' \
--output table

describe-spot-price-history — AWS CLI 1.36.3 Command Reference
describe-spot-price-history Description Describes the Spot price history. For more information, see Spot Instance pricing history in the Amazon EC2 User Guide . When you specify a start and end time, the operation returns the prices of the instance types w
docs.aws.amazon.com
https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-spot-price-history.html
- python 을 통해서 확인하기
import boto3
from datetime import datetime, timedelta
# AWS 클라이언트 생성
ec2_client = boto3.client('ec2')
# 변수 설정
instance_type = 't3.medium' # 확인할 EC2 인스턴스 타입
product_description = 'Linux/UNIX' # 운영 체제
availability_zone = 'ap-northeast-2a' # 가용 영역
start_time = (datetime.utcnow() - timedelta(hours=1)).isoformat() # 최근 1시간 동안의 기록
# Spot 가격 이력 조회
response = ec2_client.describe_spot_price_history(
InstanceTypes=[instance_type],
ProductDescriptions=[product_description],
AvailabilityZone=availability_zone,
StartTime=start_time
)
# 결과 출력
print(f"Spot Price History for {instance_type} in {availability_zone}:\n")
for price in response['SpotPriceHistory']:
print(f"Timestamp: {price['Timestamp']}, Price: ${price['SpotPrice']}")

describe_spot_price_history - Boto3 1.35.6 documentation
Previous describe_spot_instance_requests
boto3.amazonaws.com