skip to Main Content

I have about 50 tables in DynamoDB and I’m looking for a way to find size of all tables.

aws dynamodb describe-table --table-name [table name]

I know above command returns TableSizeBytes, but is this the only way to get size of table?
Do I have to run this command for all tables in picture?
Also, what is the cost of running this command?

2

Answers


  1. DescribeTable API is free to invoke on DynamoDB. Your only way is to iterate through all the tables and sum up the values, but I don’t get why that might be an issue.

    If you don’t want to list all tables by hand, here’s a one liner, just for fun:

    aws dynamodb list-tables --region us-east-1 | 
      jq -r '.TableNames[]' | 
      xargs -L1 -I'{}' bash -c 'aws dynamodb describe-table --table-name {} --region us-east-1 | jq -r ".Table.TableSizeBytes"' | 
      awk '{S+=$1} END {print S}'
    
    Login or Signup to reply.
  2. Just write a script and loop over all your tables. As already stated there’s no cost for running the command.

    For example:

    #!/usr/bin/env bash
    
    YOUR_DYNAMODB_TABLES=( "table1" "table2" "table3" )
    TOTAL_SIZE=0
    for TABLE in "${YOUR_DYNAMODB_TABLES[@]}"
    do
        SIZE=$(aws dynamodb describe-table --table-name "$TABLE" | jq '.Table.TableSizeBytes')
        TOTAL_SIZE=$((TOTAL_SIZE + SIZE))
    done
    echo $TOTAL_SIZE
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search