AWS 料金見積もりツールを AWS CLI で使ってみた
Generating estimates with Pricing Calculator - AWS Cost Management
強化された AWS Pricing Calculator (パブリックプレビュー)でパーソナライズされたコスト見積もりを作成しましょう | Amazon Web Services ブログ
bcm-pricing-calculator — AWS CLI 2.24.5 Command Reference
API も提供されていたため AWS CLI で使ってみました。
使ってみた
まずは create-bill-scenario コマンドで請求シナリオを作成します。
$ aws bcm-pricing-calculator create-bill-scenario --name ec2
# レスポンス
{
"id": "d15a676e-9a17-40e0-9397-4f841fc062ca",
"name": "ec2",
"billInterval": {
"start": "2025-01-01T00:00:00+00:00",
"end": "2025-02-01T00:00:00+00:00"
},
"status": "READY",
"createdAt": "2025-02-17T12:02:57.568000+00:00",
"expiresAt": "2025-02-28T23:59:59+00:00"
}
batch-create-bill-scenario-usage-modification コマンドで請求シナリオに新しいサービスを追加してみます。
今回は t2.micro の Linux EC2 インスタンスを 10 時間稼働させる場合の見積もりを作成しました。
$ aws bcm-pricing-calculator batch-create-bill-scenario-usage-modification \
--bill-scenario-id d15a676e-9a17-40e0-9397-4f841fc062ca \
--usage-modifications '[{
"amounts": [{
"amount": 10,
"startHour": 1735689600
}],
"group": "group1",
"key": "001",
"operation": "RunInstances",
"serviceCode": "AmazonEC2",
"usageAccountId": "006226652065",
"usageType": "APN1-BoxUsage:t2.micro"
}]'
# レスポンス
{
"items": [
{
"serviceCode": "AmazonEC2",
"usageType": "APN1-BoxUsage:t2.micro",
"operation": "RunInstances",
"location": "ap-northeast-1",
"id": "bd00eb83-f134-4ee9-8eda-0b3533a23046",
"group": "group1",
"usageAccountId": "012345678901",
"quantities": [
{
"startHour": "2025-01-01T00:00:00+00:00",
"unit": "Hrs",
"amount": 10.0
}
],
"key": "001"
}
],
"errors": []
}
create-bill-estimate コマンドで上記請求シナリオのレポートを発行します。
$ aws bcm-pricing-calculator create-bill-estimate \
--bill-scenario-id d15a676e-9a17-40e0-9397-4f841fc062ca \
--name ec2-report
# レスポンス
{
"id": "387555ad-bdec-45f0-8629-edd4dc9c5bb1",
"name": "ec2-report",
"status": "IN_PROGRESS",
"billInterval": {
"start": "2025-01-01T00:00:00+00:00",
"end": "2025-02-01T00:00:00+00:00"
},
"costSummary": {
"totalCostDifference": {
"historicalCost": {
"amount": 0.0
},
"estimatedCost": {
"amount": 0.0
}
},
"serviceCostDifferences": {}
},
"createdAt": "2025-02-17T12:04:59.825000+00:00",
"expiresAt": "2026-03-17T12:04:59.825000+00:00"
}
レポートの発行状況については get-bill-estimate コマンドで確認できます。
発行直後はステータスが IN_PROGRESS
なので、10 ~ 20 分ほど待つ必要がありました。
$ aws bcm-pricing-calculator get-bill-estimate \
--identifier 387555ad-bdec-45f0-8629-edd4dc9c5bb1
# レスポンス
{
"id": "387555ad-bdec-45f0-8629-edd4dc9c5bb1",
"name": "ec2-report",
"status": "IN_PROGRESS",
"billInterval": {
"start": "2025-01-01T00:00:00+00:00",
"end": "2025-02-01T00:00:00+00:00"
},
"costSummary": {
"totalCostDifference": {
"historicalCost": {
"amount": 0.0
},
"estimatedCost": {
"amount": 0.0
}
},
"serviceCostDifferences": {}
},
"createdAt": "2025-02-17T12:04:59.825000+00:00",
"expiresAt": "2026-03-17T12:04:59.825000+00:00"
}
レポート発行完了後に再度 get-bill-estimate
コマンドを実行します。
$ aws bcm-pricing-calculator get-bill-estimate \
--identifier ddb6cdaf-4ad1-4ddb-b711-372a841fbc8c
# レスポンス
{
"id": "387555ad-bdec-45f0-8629-edd4dc9c5bb1",
"name": "ec2-report",
"status": "COMPLETE",
"billInterval": {
"start": "2025-01-01T00:00:00+00:00",
"end": "2025-02-01T00:00:00+00:00"
},
"costSummary": {
"totalCostDifference": {
"historicalCost": {
"amount": 1.1509248519,
"currency": "USD"
},
"estimatedCost": {
"amount": 1.3029248519,
"currency": "USD"
}
},
"serviceCostDifferences": {
"AmazonEC2": {
"historicalCost": {
"amount": 0.0,
"currency": "USD"
},
"estimatedCost": {
"amount": 0.152,
"currency": "USD"
}
}
}
},
"createdAt": "2025-02-17T12:04:59.825000+00:00",
"expiresAt": "2026-03-17T12:04:59.825000+00:00"
}
estimatedCost
を確認すると 0.152 USD であり、t2.micro の EC2 インスタンスを東京リージョンで 10 時間稼働させた料金と一致します。
オンデマンドインスタンスの料金 - Amazon EC2 (仮想サーバー) | AWS
t2.micro USD 0.0152
0.0152 * 10 = 0.152
AWS CLI 経由でも料金見積もりができることを確認できました。
まとめ
今回は AWS 料金見積もりツールを AWS CLI で使ってみました。
どなたかの参考になれば幸いです。
参考資料
- Generating estimates with Pricing Calculator - AWS Cost Management
- 強化された AWS Pricing Calculator (パブリックプレビュー)でパーソナライズされたコスト見積もりを作成しましょう | Amazon Web Services ブログ
- create-bill-scenario — AWS CLI 2.24.5 Command Reference
- batch-create-bill-scenario-usage-modification — AWS CLI 2.24.5 Command Reference
- create-bill-estimate — AWS CLI 2.24.5 Command Reference
- get-bill-estimate — AWS CLI 2.24.5 Command Reference
- オンデマンドインスタンスの料金 - Amazon EC2 (仮想サーバー) | AWS
Discussion