in ddbtools/table.py [0:0]
def estimate_current_table_costs(self, provisioned_capacity_pricing: dict,
replicated_write_pricing: dict,
storage_pricing: dict,
table_pricing_data: dict) -> dict:
"""Calculate monthly storage and throughput costs for a table for all storage classes"""
# storage costs
ia_monthly_storage_cost = table_pricing_data[constants.SIZE_IN_GB] * storage_pricing[constants.IA_VOLUME_TYPE]
std_monthly_storage_cost = table_pricing_data[constants.SIZE_IN_GB] * storage_pricing[constants.STD_VOLUME_TYPE]
# read capacity costs
ia_monthly_rcu_cost = (table_pricing_data[constants.PROVISIONED_RCUS]
* provisioned_capacity_pricing[constants.IA_RCU_PRICING]
* constants.HOURS_IN_MONTH)
std_monthly_rcu_cost = (table_pricing_data[constants.PROVISIONED_RCUS]
* provisioned_capacity_pricing[constants.STD_RCU_PRICING]
* constants.HOURS_IN_MONTH)
# write capacity costs
ia_monthly_wcu_cost = None
std_monthly_wcu_cost = None
# If the table has replicas, estimate rWCUs instead of WCUs
if constants.REPLICAS in table_pricing_data:
ia_monthly_wcu_cost = (table_pricing_data[constants.PROVISIONED_RCUS]
* replicated_write_pricing[constants.REPLICATED_IA_WCU_PRICING]
* constants.HOURS_IN_MONTH)
std_monthly_wcu_cost = (table_pricing_data[constants.PROVISIONED_RCUS]
* replicated_write_pricing[constants.REPLICATED_STD_WCU_PRICING]
* constants.HOURS_IN_MONTH)
else:
ia_monthly_wcu_cost = (table_pricing_data[constants.PROVISIONED_WCUS]
* provisioned_capacity_pricing[constants.IA_WCU_PRICING]
* constants.HOURS_IN_MONTH)
std_monthly_wcu_cost = (table_pricing_data[constants.PROVISIONED_WCUS]
* provisioned_capacity_pricing[constants.STD_WCU_PRICING]
* constants.HOURS_IN_MONTH)
# total costs
ia_monthly_total_cost = ia_monthly_storage_cost + ia_monthly_rcu_cost + ia_monthly_wcu_cost
std_monthly_total_cost = std_monthly_storage_cost + std_monthly_rcu_cost + std_monthly_wcu_cost
estimated_table_costs = {constants.STD_MO_STORAGE_COST: std_monthly_storage_cost,
constants.STD_MO_RCU_COST: std_monthly_rcu_cost,
constants.STD_MO_WCU_COST: std_monthly_wcu_cost,
constants.STD_MO_TOTAL_COST: std_monthly_total_cost,
constants.IA_MO_STORAGE_COST: ia_monthly_storage_cost,
constants.IA_MO_RCU_COST: ia_monthly_rcu_cost,
constants.IA_MO_WCU_COST: ia_monthly_wcu_cost,
constants.IA_MO_TOTAL_COST: ia_monthly_total_cost}
estimated_table_costs[constants.TOTAL_STD_MO_COSTS] = std_monthly_total_cost
estimated_table_costs[constants.TOTAL_IA_MO_COSTS] = ia_monthly_total_cost
# GSI costs
# TODO: refactor GSI and table cost estimating out into a single method
estimated_gsi_costs = None
if constants.GSIS in table_pricing_data:
estimated_gsi_costs = []
total_gsi_std_costs = Decimal(0)
total_gsi_ia_costs = Decimal(0)
for gsi_data in table_pricing_data[constants.GSIS]:
gsi_ia_mo_storage_cost = gsi_data[constants.SIZE_IN_GB] * storage_pricing[constants.IA_VOLUME_TYPE]
gsi_std_mo_storage_cost = gsi_data[constants.SIZE_IN_GB] * storage_pricing[constants.STD_VOLUME_TYPE]
gsi_ia_mo_rcu_cost = (gsi_data[constants.PROVISIONED_RCUS]
* provisioned_capacity_pricing[constants.IA_RCU_PRICING]
* constants.HOURS_IN_MONTH)
gsi_std_mo_rcu_cost = (gsi_data[constants.PROVISIONED_RCUS]
* provisioned_capacity_pricing[constants.STD_RCU_PRICING]
* constants.HOURS_IN_MONTH)
gsi_ia_mo_wcu_cost = (gsi_data[constants.PROVISIONED_WCUS]
* provisioned_capacity_pricing[constants.IA_WCU_PRICING]
* constants.HOURS_IN_MONTH)
gsi_std_mo_wcu_cost = (gsi_data[constants.PROVISIONED_WCUS]
* provisioned_capacity_pricing[constants.STD_WCU_PRICING]
* constants.HOURS_IN_MONTH)
gsi_ia_mo_total_cost = gsi_ia_mo_storage_cost + gsi_ia_mo_rcu_cost + gsi_ia_mo_wcu_cost
total_gsi_ia_costs += gsi_ia_mo_total_cost
gsi_std_mo_total_cost = gsi_std_mo_storage_cost + gsi_std_mo_rcu_cost + gsi_std_mo_wcu_cost
total_gsi_std_costs += gsi_std_mo_total_cost
gsi_costs = {constants.INDEX_NAME: gsi_data[constants.INDEX_NAME],
constants.INDEX_ARN: gsi_data[constants.INDEX_ARN],
constants.STD_MO_STORAGE_COST: gsi_std_mo_storage_cost,
constants.STD_MO_RCU_COST: gsi_std_mo_rcu_cost,
constants.STD_MO_WCU_COST: gsi_std_mo_wcu_cost,
constants.STD_MO_TOTAL_COST: gsi_std_mo_total_cost,
constants.IA_MO_STORAGE_COST: gsi_ia_mo_storage_cost,
constants.IA_MO_RCU_COST: gsi_ia_mo_rcu_cost,
constants.IA_MO_WCU_COST: gsi_ia_mo_wcu_cost,
constants.IA_MO_TOTAL_COST: gsi_ia_mo_total_cost}
estimated_gsi_costs.append(gsi_costs)
if estimated_gsi_costs is not None:
estimated_table_costs[constants.GSI_MONTHLY_COSTS] = estimated_gsi_costs
estimated_table_costs[constants.TOTAL_STD_MO_COSTS] += total_gsi_std_costs
estimated_table_costs[constants.TOTAL_IA_MO_COSTS] += total_gsi_ia_costs
return estimated_table_costs