記事:
注意点:
記事:
profile=example region=us-east-1 aws cost-optimization-hub list-recommendations --profile $profile --region $region --order-by 'dimension=EstimatedMonthlySavings,order=Desc' # accountId, Nameタグだけ欲しい場合 --query 'items[].{C010:accountId,C020:tags[?key==`Name`].value|[0]}'
SUM(line_item_unblended_cost) AS cost
AND line_item_line_item_type NOT IN ('Tax','Refund','Credit')
SELECT bill_billing_period_start_date AS TIME, 'Tax' AS product, SUM(line_item_unblended_cost) AS cost FROM monthly WHERE $__timeFilter(bill_billing_period_start_date) AND line_item_usage_account_id IN ($Account_id) AND line_item_line_item_type IN ('Tax','Refund','Credit') GROUP BY 1, 2 ORDER BY 1
SELECT bill_billing_period_start_date, line_item_product_code, sum(line_item_unblended_cost) as cost from monthly where bill_billing_period_start_date BETWEEN TIMESTAMP '2023-10-01 00:00:00' AND TIMESTAMP '2023-10-30 23:59:59' and line_item_line_item_type in ('Fee') and reservation_reservation_a_r_n != '' group by 1,2 order by 1
SELECT DISTINCT line_item_product_code FROM monthly WHERE bill_billing_period_start_date BETWEEN (CURRENT_TIMESTAMP - INTERVAL '90' DAY) AND (CURRENT_TIMESTAMP - INTERVAL '1' DAY) ;
profile=example # durationsを指定して、offeringIdを取得。describe-savings-plans-offering-ratesではdurationsで絞り込めない。 aws savingsplans describe-savings-plans-offerings \ --product-type EC2 \ --plan-types Compute \ --payment-options "Partial Upfront" \ --durations $((3600*24*365)) \ --currencies USD \ --profile $profile { "searchResults": [ { "offeringId": "8a5f1067-1eba-46cd-804c-4eb74c0fd43b", "productTypes": [ "Fargate", "EC2", "Lambda" ], "planType": "Compute", "description": "1 year Partial Upfront Compute Savings Plan", "paymentOption": "Partial Upfront", "durationSeconds": 31536000, "currency": "USD", "serviceCode": "ComputeSavingsPlans", "usageType": "ComputeSP:1yrPartialUpfront", "operation": "", "properties": [] } ], "nextToken": "11111114011AKXHi82LDrvXSYuU4NaQhgqffGWGkm7NYgDgGhZp2asyvYVUZFiQNU1YBhoBJF" } # 検索したいリージョン、インスタンスタイプ region=ap-northeast-1 instanceType=t3.medium # durationSeconds: 1年 # usageType: BoxUsage のみ aws savingsplans describe-savings-plans-offering-rates \ --savings-plan-payment-options "Partial Upfront" \ --products EC2 \ --savings-plan-types Compute \ --operations RunInstances \ --filters "name=region,values=$region" "name=instanceType,values=$instanceType" "name=tenancy,values=shared" \ --profile $profile \ | jq '.searchResults[] | select(.savingsPlanOffering.durationSeconds == '$((3600*24*365))') | select(.usageType | contains("BoxUsage"))' { "savingsPlanOffering": { "offeringId": "8a5f1067-1eba-46cd-804c-4eb74c0fd43b", "paymentOption": "Partial Upfront", "planType": "Compute", "durationSeconds": 31536000, "currency": "USD", "planDescription": "1 year Partial Upfront Compute Savings Plan" }, "rate": "0.0407", "unit": "Hrs", "productType": "EC2", "serviceCode": "AmazonEC2", "usageType": "APN1-BoxUsage:t3.medium", "operation": "RunInstances", "properties": [ { "name": "instanceFamily", "value": "t3" }, { "name": "productDescription", "value": "Linux/UNIX" }, { "name": "instanceType", "value": "t3.medium" }, { "name": "tenancy", "value": "shared" }, { "name": "region", "value": "ap-northeast-1" } ] }
料金計算:
例1:
paymentOption | rate (Savings Plans の料金) | オンデマンドと比較した費用節減 |
No Upfront | 0.0427 | 22% |
Partial Upfront | 0.0407 | 25% |
# Hourly commitment houry_commit=0.043 # Total cost: 1 year total_cost=$(echo "${houry_commit}*24*365" | bc); echo $total_cost 376.680 # Monthly payment: monthly_cost=$(echo "scale=2;${total_cost}/12" | bc); echo $monthly_cost 31.39
# Hourly commitment houry_commit=0.041 # Total cost: 1 year total_cost=$(echo "${houry_commit}*24*365" | bc); echo $total_cost 359.160 # Upfront cost: upfront_cost=$(echo "${total_cost}*0.5" | bc); echo $upfront_cost 179.580 # Monthly payment: monthly_cost=$(echo "scale=2;(${total_cost} - ${upfront_cost}) / 12" | bc); echo $monthly_cost 14.96
日々どれだけコストがかかっている事をエンジニアも確認した方が良い。
無駄な費用を払わないように、コスト意識を持たせる。
設定が必要だが、EC2,RDSといったリソースにタグを振ると、s3バケット上のCSVにそのタグが表示される。
そのため、CSVをExcel等のピボットテーブルで集計するとタグごとのコストが分かる。
ただし、現在全てのリソースにタグをふれないため、金額を厳密に分けたい場合(例えば、クライアント会社毎に請求書を作る)は、別のAWSアカウントを作成し、Consolidated BillingでメインのAWSアカウントに請求をまとめた方が良い。
リザーブドインスタンス を購入したアカウントを解約すると、リザーブドインスタンス が期限切れになるか、解約したアカウントが完全に削除されるまで、支払いアカウントに リザーブドインスタンス の請求が継続されます。解約したアカウントは 90 日後に完全に削除されます。削除後、メンバーアカウントは リザーブドインスタンス の請求割引を受けられなくなります。