管理人Kのひとりごと

デジモノレビューやプログラミングや写真など

AWSのサポート費用を計算する(python)

AWSのサポートプランの一部(ビジネス、エンタープライズ)では、月の利用料金に応じて段階的にサポート費用が変動します。利用料金に応じたサポート費用を試算するため、pythonでスクリプトを書いてみました。

サポート費用の求め方(ビジネス)

いずれか大きい方
100 USD または
以下の計算結果
月額 AWS 使用料のうち最初の0 – 10,000 USD の10%
月額 AWS 使用料のうち10,000 – 80,000 USD に対しては 7%
月額 AWS 使用料のうち80,000 – 250,000 USD に対しては5%
月額 AWS 使用料のうち250,000 USD を超える分に対しては3%

AWS サポート(ビジネス)料金の例
月額 AWS 使用料が 85,000 USD の場合:

10,000 USD x 10% = 1,000 USD
(月額使用料のうち最初の 0~10,000 USD 分の 10%)

  1. 70,000 USD x 7% = 4,900 USD

(月額使用料のうち 10,000~80,000 USD 分の 7%)

  1. 5,000 USD x 5% = 250 USD

(月額使用料のうち 80,000~250,000 USD 分の 5%)

  1. 0 USD x 3% = 0 USD

(月額使用料のうち 250,000 USD を超える分の 3%)
合計: 6,150 USD

pythonでの計算例

10%,7%,5%,3%の各ランクでの計算を合算する必要がありますが、3%→10%に向かって計算しました。

#!/usr/bin/python
# -*- coding:utf-8 -*-

import sys

def calc_support_fee(monthly_usage_fee, support_fee):
    if monthly_usage_fee > 250000:
        support_fee += (monthly_usage_fee - 250000) * 0.03
        return calc_support_fee(250000, support_fee)
    elif monthly_usage_fee > 80000:
        support_fee += (monthly_usage_fee - 80000) * 0.05
        return calc_support_fee(80000, support_fee)
    elif monthly_usage_fee > 10000:
        support_fee += (monthly_usage_fee - 10000) * 0.07
        return calc_support_fee(10000, support_fee)
    else:
        support_fee += monthly_usage_fee * 0.1
        monthly_usage_fee = 0

    if support_fee < 100:
        support_fee = 100

    if monthly_usage_fee == 0:
        return support_fee


if __name__ == '__main__':
    args = sys.argv

    print calc_support_fee(float(args[1]), 0.0)
hoge@localhost:~ $ python calc_aws_support_fee.py 85000
6150.0