Kanji
・클라우드 엔지니어 / 프리랜서 ・1993년생 ・에히메현 출신 / 도쿄도 시부야구 거주 ・AWS 경력 5년 프로필 상세
목차
GetUsageLinesEstimatedCost
ap-northeast-1
usageType
key
사내 시스템의 클라우드 마이그레이션과 AWS 인프라 구축을 진행하면서 제가 늘 속을 태웠던 문제는 ’사전 비용 산정의 번거로움과 월말 청구서를 열어보는 순간의 두려움’이었습니다.
개발자가 Terraform이나 AWS CDK로 손쉽게 리소스를 프로비저닝하거나, 최근에는 자율형 AI 에이전트(Antigravity, Claude Code, OpenCode 등)에게 자연어 프롬프트로 “검증용 스테이징 환경을 구성해 줘”라고 지시하면 불과 몇 분 만에 VPC, NAT Gateway, EKS 클러스터, 검증용 RDS, 배스천 EC2가 깔끔하게 생성됩니다.
하지만 이 빠른 속도 이면에는 ’의도치 않은 오버스펙이나 고비용 리소스 생성’이라는 함정이 숨어 있습니다. 예전에 한 검증 프로젝트에서 개발자가 Multi-AZ로 NAT Gateway를 이중화하고 대용량 컨테이너 이미지 풀과 로그 전송을 반복한 결과, 단 일주일 만에 수백 달러의 데이터 전송 및 게이트웨이 요금이 발생해 월말 결제 알림을 받고 급히 삭제했던 뼈아픈 경험이 있습니다.
이러한 사고를 예방하기 위해 Pull Request(PR) 단계에서 “이 인프라 변경으로 월 비용이 얼마나 증가하는가”를 자동 계산하고, 예산 초과 시 CI를 차단하는 FinOps 가드레일을 구축하려 여러 번 시도했습니다. 그러나 기존 AWS 환경에는 높은 장벽이 존재했습니다.
pricing:GetProducts
“AWS 공식 네이티브 API로 리소스 사용량 명세만 던지면 계정에 아무것도 저장하지 않고 즉시 합계 금액을 반환해 주는 무상태(Stateless) API는 없을까?”
2026년 11월 20일, 마침내 AWS Billing and Cost Management (BCM) Pricing Calculator의 새로운 API 액션인 GetUsageLinesEstimatedCost 가 정식 출시되었습니다.
▲ Terraform CI/CD 및 자율형 AI 에이전트가 AWS Pricing Calculator API를 통해 무상태로 사전 비용을 즉시 추계하고 예산 가드레일을 적용하는 아키텍처
새롭게 등장한 GetUsageLinesEstimatedCost 의 가장 큰 특징은 ‘AWS 계정에 견적(Workload나 Scenario)을 영구 저장할 필요가 전혀 없는 완전 무상태(Stateless) 구조’ 라는 점입니다.
usage
rateType
BEFORE_DISCOUNTS
AFTER_DISCOUNTS
AFTER_DISCOUNTS_AND_COMMITMENTS
[a-zA-Z0-9]*
lineItems
errors
Hrs
GB-Mo
estimatedCost
totalCost
원격 검증 환경에서 최신 AWS CLI v2(v2.42.1)를 사용하여 도쿄 리전( ap-northeast-1 )의 표준 구성( t3.medium 1대 730시간, gp3 100GB, NAT Gateway 1기 730시간)을 일괄 추계한 결과입니다.
t3.medium
gp3
요청용 JSON( usage-request.json )을 작성합니다. 최상위 배열 키는 "usage" 이며 각 항목의 "key" 는 10자 이내의 영숫자(하이픈 불가) 여야 합니다.
usage-request.json
"usage"
"key"
{ "rateType": "BEFORE_DISCOUNTS", "usage": [ { "key": "webEc201", "serviceCode": "AmazonEC2", "usageType": "APN1-BoxUsage:t3.medium", "operation": "RunInstances", "amount": 730.0 }, { "key": "webEbs01", "serviceCode": "AmazonEC2", "usageType": "APN1-EBS:VolumeUsage.gp3", "operation": "CreateVolume", "amount": 100.0 }, { "key": "natGw01", "serviceCode": "AmazonEC2", "usageType": "APN1-NatGateway-Hours", "operation": "CreateNatGateway", "amount": 730.0 } ] }
CLI 명령어를 실행합니다.
$ aws bcm-pricing-calculator get-usage-lines-estimated-cost \ --cli-input-json file://usage-request.json \ --region us-east-1
반환된 실제 응답은 다음과 같습니다.
{ "rateType": "BEFORE_DISCOUNTS", "totalCost": 89.62, "currency": "USD", "lineItems": [ { "key": "webEc201", "serviceCode": "AmazonEC2", "usageType": "APN1-BoxUsage:t3.medium", "operation": "RunInstances", "estimatedCost": { "usageAmount": 730.0, "usageUnit": "Hrs", "cost": 37.96, "currency": "USD" } }, { "key": "webEbs01", "serviceCode": "AmazonEC2", "usageType": "APN1-EBS:VolumeUsage.gp3", "operation": "CreateVolume", "estimatedCost": { "usageAmount": 100.0, "usageUnit": "GB-Mo", "cost": 9.60, "currency": "USD" } }, { "key": "natGw01", "serviceCode": "AmazonEC2", "usageType": "APN1-NatGateway-Hours", "operation": "CreateNatGateway", "estimatedCost": { "usageAmount": 730.0, "usageUnit": "Hrs", "cost": 42.06, "currency": "USD" } } ], "errors": [] }
▲ 원격 검증 환경에서 AWS CLI를 실행하여 3개 사용량 명세로부터 월 $89.62의 견적이 단일 요청(384ms)으로 산출된 모습
min: 0, max: 10, pattern: [a-zA-Z0-9]*
aws_instance.web-server
ValidationException
item000001
us-east-1
BoxUsage:t3.medium
APN1-BoxUsage:t3.medium
APN1-
errorCode: "NOT_FOUND"
pricing:
bcm-pricing-calculator:
최소 권한 IAM 정책은 다음과 같이 설정합니다.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowGetUsageLinesEstimatedCostOnly", "Effect": "Allow", "Action": [ "bcm-pricing-calculator:GetUsageLinesEstimatedCost" ], "Resource": "*" } ] }
단일 요청당 최대 500건 제한이 있으므로, 대규모 Terraform 변경 시 500건 단위로 슬라이싱하여 호출한 뒤 totalCost 를 합산합니다.
#!/usr/bin/env python3 """ AWS Pricing Calculator API (GetUsageLinesEstimatedCost) 기반 실시간 사전 비용 추계 및 FinOps 가드레일 스크립트 """ import sys import boto3 from botocore.exceptions import ClientError def chunk_list(items, chunk_size=500): for i in range(0, len(items), chunk_size): yield items[i : i + chunk_size] def estimate_workload_costs(usage_lines, rate_type="BEFORE_DISCOUNTS", region_name="us-east-1"): client = boto3.client("bcm-pricing-calculator", region_name=region_name) total_cost = 0.0 all_line_items = [] all_errors = [] for chunk_idx, chunk in enumerate(chunk_list(usage_lines, 500)): key_map = {} api_usage_payload = [] for idx, item in enumerate(chunk): short_key = f"item{chunk_idx:02d}{idx:04d}" key_map[short_key] = item.get("label", short_key) api_usage_payload.append({ "key": short_key, "serviceCode": item["serviceCode"], "usageType": item["usageType"], "operation": item["operation"], "amount": float(item["amount"]), }) try: response = client.get_usage_lines_estimated_cost( rateType=rate_type, usage=api_usage_payload, ) total_cost += response.get("totalCost", 0.0) for priced in response.get("lineItems", []): priced["originalLabel"] = key_map.get(priced["key"], priced["key"]) all_line_items.append(priced) for err in response.get("errors", []): err["originalLabel"] = key_map.get(err["key"], err["key"]) all_errors.append(err) except ClientError as e: print(f"[ERROR] API 호출 실패: {e}", file=sys.stderr) raise e return { "rateType": rate_type, "totalCost": round(total_cost, 2), "currency": "USD", "lineItems": all_line_items, "errors": all_errors, } def enforce_finops_budget(estimation_result, monthly_budget_threshold=100.0): cost = estimation_result["totalCost"] errors = estimation_result["errors"] print("========================================") print(" FinOps 사전 비용 추계 리포트 ") print("========================================") print(f"적용 요율 유형 : {estimation_result['rateType']}") print(f"추계 월간 총비용 : ${cost:.2f} USD") print(f"설정 월간 예산 : ${monthly_budget_threshold:.2f} USD") if errors: print(f"\n[BLOCKED] 🚨 미산출 에러 {len(errors)}건 발생 (Fail-Closed 차단)") return False if cost > monthly_budget_threshold: print(f"[BLOCKED] 🚨 월간 예산 상한(${monthly_budget_threshold:.2f})을 초과했습니다!") return False else: print(f"[PASSED] ✅ 예산 이내입니다. 배포를 계속할 수 있습니다.") return True if __name__ == "__main__": sample_usage = [ { "label": "prod-app-server-t3-large", "serviceCode": "AmazonEC2", "usageType": "APN1-BoxUsage:t3.large", "operation": "RunInstances", "amount": 730.0, }, { "label": "prod-app-db-gp3", "serviceCode": "AmazonEC2", "usageType": "APN1-EBS:VolumeUsage.gp3", "operation": "CreateVolume", "amount": 200.0, }, ] result = estimate_workload_costs(sample_usage, rate_type="BEFORE_DISCOUNTS") if not enforce_finops_budget(result, monthly_budget_threshold=50.0): sys.exit(1)
▲ 원격 검증 환경에서의 에러 격리 테스트(NOT_FOUND) 및 Python FinOps 가드레일에 의한 예산 초과 차단($95.12 > $50.00) 실행 결과
자율형 코딩 에이전트(Antigravity, Claude Code, OpenCode 등)의 MCP 도구로 GetUsageLinesEstimatedCost 를 연동하면, 에이전트가 인프라를 프로비저닝하기 전에 스스로 증분 비용을 계산하고 예산 초과 시 Graviton 인스턴스나 gp3 스토리지로 자율 최적화하는 안전망을 구축할 수 있습니다.
bcm-pricing-calculator:GetUsageLinesEstimatedCost
Real-time AI quant analysis of corporate earnings reports.
실전 같은 AI 음성 모의 통화와 5축 정밀 피드백. 16강 인터랙티브 강의와 스튜디오급 AI 프로필 생성 지원.
영수증 촬영 즉시 Gemini AI가 품목과 금액을 자동 인식. 모임 및 여행 경비를 손쉽게 더치페이하고 정산합니다.
점술사, 집사, 바텐더 AI 캐릭터가 직접 게임을 진행하고 대화 주제를 던져 모임을 흥미진진하게 만듭니다.
人工甘味料や添加物のNG除外と有効成分あたりの実質単価比較データベース。