Package: dynamodb-lens
DynamoDB LensA set of tools to help understand DynamoDB table performance capabilities and potential cost optimization opportunities.Installation and usageInstallationpython3-mpipinstalldynamodb-lensCLI usageusage:cli[-h]--table_nameTABLE_NAME[--metric_consumed_period_sMETRIC_CONSUMED_PERIOD_S][--save_analysis][--verbose]options:-h,--helpshowthishelpmessageandexit--table_nameTABLE_NAME--metric_consumed_period_sMETRIC_CONSUMED_PERIOD_SThecloudwatchmetricperiodforconsumedWCU/RCU--save_analysissavethejsonformattedanalysistoafile--verbosePrintthefullanalysis,otherwiseasummarywillbeprinted
python3-mdynamodb_lens.cli--table_namesentences1--metric_consumed_period_s60--verbose--save_analysisTable AnalyzerThis library analyzes a table's current state, configuration and usage in order to estimate performance capabilities.A DynamoDB Table's current partition count as well as table settings will determine its performance capabilities.Partition count is not exposed directly, but we can infer the number of partitions in several ways:Count the number of Open DynamoDB Stream shards, it is a 1:1 mapping of Open shards to PartitionsCheck cloudwatch max Provisioned settings over the last 3 monthsCheck cloudwatch max consumed WCU/RCU over the last 1 month (more accurate if consumed_period_s set to 60)Check current WCU/RCU settings on the table if Provisioned mode is currently configuredCheck the current storage utilization of the tableIf Streams is not enabled, this program will estimate current number of partitions based on the maximum WCU/RCU values
calculated from the data gathered in #2-5 above.DynamoDB tables never give back partitions once they've been allocated.This is what is meant by"previous peak" in  the documentation.This program is more accurate if DynamoDB Streams is enabled for the table.Enabling streams is outside the scope of this program, it can be done via:aws dynamodb update-table --table-name <value> --stream-specification StreamEnabled=true,StreamViewType=KEYS_ONLYand disabled with:aws dynamodb update-table --table-name <value> --stream-specification StreamEnabled=falsePlease review the documentation and understand the implications of running these commands before executing them.TableAnalyzer class usageThe class can be imported and called directly if thedynamodb_lens.clidoesn't fit the use caseThe only required parameter is table_name, and optionallyverbose=True|Falseplus already instantiated boto3 clients can be passed in.fromdynamodb_lens.analyzerimportTableAnalyzerfromdynamodb_lens.utilsimportreturn_boto3_clienttable=TableAnalyzer(table_name='foo',consumed_period_s=60,lambda_client=return_boto3_client('lambda'),ddbs_client=return_boto3_client('dynamodbstreams'),ddb_client=return_boto3_client('dynamodb'),cw_client=return_boto3_client('cloudwatch'),verbose=False)table.print_analysis()TableAnalyzer.analysisThe main purpose of TableAnalyzer is to produce a json-formatted analysis variable.Syntax{"TableDescription":{dict},"StreamDescription":{dict},"EstimationData":{"Description":"Raw estimation data used for debugging purposes only!","WCU":{"CurrentProvisionedWCU":int,"MaxConsumedWCU":int,"MaxProvisionedWCU":int},"RCU":{"CurrentProvisionedRCU":int,"MaxConsumedRCU":int,"MaxProvisionedRCU":int},"Partitions":{"MaxProvisionedWCU":int,"MaxProvisionedRCU":int,"CurrentTableSize":int}},"Summary":{"TableName":"string","TableArn":"string","DeletionProtection":boolean,"SizeMB":int,"ItemCount":int,"BillingMode":"ON-DEMAND|PROVISIONED","StreamArn":"string","Estimations":{"EstimationMethod":"StreamOpenShards|OnDemandBaseSpecs|CurrentTableSize|CurrentProvisionedWCU|CurrentProvisionedRCU|MaxConsumedWCU|MaxConsumedRCU|MaxProvisionedWCU|MaxProvisionedRCU","EstimationMethodDescription":"string","Partitions":int,"TableMaximums":{"WCU":int,"WriteThroughputMBs":int,"RCU":{"Base":int,"EventuallyConsistent":int},"ReadThroughputMBs":{"Base":int,"EventuallyConsistent":int}},"PartitionMaximums":{"Comments":"string","WCU":int,"WriteThroughputMBs":int,"RCU":{"Base":int,"EventuallyConsistent":int},"ReadThroughputMBs":{"Base":int,"EventuallyConsistent":int}}}}}StructureTableDescription (dict)requiresself.verbose = TrueThe boto3 dynamodb client.describe_table response. Seehttps://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/describe_table.htmlStreamDescription (dict)requiresself.verbose = TrueThe boto3 dynamodbstreams client.describe_stream response. Seehttps://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodbstreams/client/describe_stream.htmlEstimationsData (dict)requiresself.verbose = TrueThis is the data used to estimate number of partitionsif streams are not enabled, primarily meant for debugging onlyWCU (dict)RCU (dict)Partitions (dict)Summary (dict)TableName (string)The name of the tableTableArn (string)The ARN of the tableDeletionProtection (bool)Is Deletion protection enabled?SizeMB (int)Size in MegabytesItemCount (int)The number of itemsBillingMode (str)ON-DEMAND: Pay per requestPROVISIONED: Pay hourly for predictable throughputStreamArn (str)The ARN of the streamEstimations (dict)EstimationMethod (string) - The method that was used to estimate the number of partitions and performance capabilitiesStreamOpenShardsWhen DynamoDB Streams are enabled for a table, we simply count the number of Open shards to determine partitionsOnDemandBaseSpecsThe table is in On-Demand mode and base table specs for on-demand were used for the calculationsCurrentTableSizeEach DynamoDB partition can be up to 10 GB in size, total size (GB)/10CurrentProvisionedWCU|CurrentProvisionedRCUThe current table specificationsMaxConsumedWCU|MaxConsumedRCU|MaxProvisionedWCU|MaxProvisionedRCUCloudwatch metricsEstimationMethodDescription (str)Describes the EstimationMethod used and whyPartitions (int)The number of partitionsIf Streams are enabled, this is 100% accurate.If we used metric data or table settings then it is an estimate.TableMaximums (dict) - Based on number of partitions and current table settings, estimate the table maximumsWCU (int)Total WriteCapacityUnitsWriteThroughputMbsTotal Write ThroughputRCU (dict)Base (int)ReadCapacityUnits for strong readsEventuallyConsistent (int)ReadCapacityUnits for eventually consistent readsReadThroughputMBs (int)Base (int)ReadThroughput in MB/s for strong readsEventuallyConsistent (int)ReadThroughput in MB/s for eventually consistent readsPartitionMaximums (dict) - Based on number of partitions and current table settings, estimate the per-partition maximumsComments (string)Comments about the partition maximumsWCU (int)Per-partition WriteCapacityUnitsWriteThroughputMbs (int)Per-partition Write ThroughputRCU (dict)Base (int)Per-partition ReadCapacityUnits for strong readsEventuallyConsistent (int)Per-partition ReadCapacityUnits for eventually consistent readsReadThroughputMBs (int)Base (int)ReadThroughput in MB/s for strong readsEventuallyConsistent (int)ReadThroughput in MB/s for eventually consistent reads