Labels

Aws (32) MySQL (20) Aurora (12) Rds (7) DynamoDB (6) Cloudformation (4) Python3 (4) Unix (3) MongoDB (1)

Friday, 5 February 2021

DynamoDB cost governance

This is a quick summary of how you can walk from understanding the dynamodb cost to make a reservation that can help you to save up to 73%

DDB Billing model (Provisioning, PPR)

DynamoDB tables can be On-Demand mode or Provisioned Capacity mode. On-demand mode is chosen for tables that are highly likely to get unpredictable spikes in Read & Write Capacity units. Provisioned mode is more for predictable workload, but even if you don't utilize all the provisioned RCU & WCU you still pay for what you provision

For table in provision mode, you can Reserve Capacity units. It's a billing discount applied on an hourly basis. There is a saving of 54% per year against the saving of 3 years for 73%. 

It is always recommended to make the reservation on the billing account if you have multi-accounts connects together.


Review usage via CW and from Billing consoles

AWS provides very useful DynamoDB metrics, you can use them to work out if a table is being used. It is a such necessary step if you have hundreds of tables and the Consumed* metrics show if you have oversized the table throughput. 

throughout the billing console, you can figure out how many EU-Consumed[Write,Read]CapacityUnits-Hrs your total of dynamoDB tables used. You can break the group of tables by using the tags but if you have not an tidy account, you won't be able to find out which table(s) has consumed a lot capacity.


Example breaking the capacity units

Go to the Cost Explorer dashboard, filter in by the API operation to "Committed Throughput" and charge type includes "Usage" you can see the daily cost.

For example the chart is reporting that it has been spent

  • Daily Write cost $ 70.58 (EU-WriteCapacityUnit-Hrs)
  • Daily Read  cost $ 28.23 (EU-ReadCapacityUnit-Hrs )

We can work out the number of WCU and RCU used in a day

  • Daily WCU consumed 4000 ( $ 70.58 / 24h / $ 0.000735 )
  • Daily RCU consumed 8000 ( $ 28.23 / 24h / $ 0.000147 )   


Useful AWS CLI 

Retrieve the table's name, its capacities the creation time, and the billing method

aws dynamodb list-table | sed 's/   "//g; s/",//g; s/{//g; s/}//g; /TableNames/d' > list_table_names
list="$(cat list_table_names)"
CONTA=0
for t in $(echo $list); do 
    ((CONTA=$CONTA+1))
    echo $CONTA $t
    aws dynamodb describe-table --table-name $t --query "Table.[TableName,ProvisionedThroughput.ReadCapacityUnits,ProvisionedThroughput.WriteCapacityUnits,BillingModeSummary.BillingMode,CreationDateTime]" --output text >> table_capacities;
done

Reserving some capacities

Let's consider that we want to benefit from the hourly basis discount and make a reservation of Read and Write capacity units.

The reservation is done at a group of 100 capacity units and for Ireland these are the costs

  • $0.000735 per WCU hour = 0.0735 100 WCU hour
  • $0.000147 per RCU hour = 0.0147 100 RCU hour


All the tables use a total of 8000 RCU and 4000 WCU

On-Demand daily$ 9.90
On-Demand annual$ 3,606.00
On-Demand 3years$ 10,818.00
Provision 1y$ 949.00
Reservation Month Cost$ 711.00
Tot Prov+Mont$ 1,660.00
Saving 1year$ 0.53
Provision 3y$ 1,139.00
Reservati Month Cost 3y$ 1,345.00
Tot Prov+Month$ 2,484.00
Saving 3year$ 0.76

There will need 168 days of On-Demand tables to spend as much as a year provisioned reservation
There will need 251 days of On-Demand tables to spend as much as three years provisioned reservation