Skip to content

Commit

Permalink
Started adding code for ddb-stream-status-distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
allanchua101 committed Dec 21, 2023
1 parent 0e66601 commit 470aa21
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cli/commands/dynamodb/ddb.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getDDBDistributionByRegion } from "./distribution/by-region.mjs";
import { getDDBDistributionByDeleteProtection } from "./distribution/by-delete-protection.mjs";
import { getDDBDistributionByTableStatus } from "./distribution/by-status.mjs";
import { getDDBDistributionByBillingMode } from "./distribution/by-billing-mode.mjs";
import { getDDBDistributionByStreamStatus } from "./distribution/by-stream-status.mjs";
// Aliases
import { runFullDynamoDBAnalysis } from "./ddb-all.mjs";

Expand Down Expand Up @@ -52,6 +53,13 @@ export const DYNAMO_STRATEGIES = [
extractorKey: DYNAMO_DB_TABLE_META_EXTRACTOR,
execute: getDDBDistributionByTableStatus,
},
{
key: "ddb-stream-status-distribution",
desc: "DynamoDB table distribution by stream status.",
extractorKey: DYNAMO_DB_TABLE_META_EXTRACTOR,
execute: getDDBDistributionByStreamStatus,
},
// Alias
{
key: "ddb",
desc: "Run full analysis on DynamoDB tables",
Expand Down
50 changes: 50 additions & 0 deletions cli/commands/dynamodb/distribution/by-stream-status.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { reduceByProp } from "#helpers/reducers/reduce-by-prop.mjs";
import { synthesizeDistribution } from "#synthesizers/distribution/synthesize-distribution.mjs";
import ENTITIES from "#constants/entities.mjs";
const BUCKETS = ["Enabled", "Disabled"];
const OUTPUT_LABEL = "DynamoDB Table Distribution by DynamoDB Stream Status";

/**
* @async
* @function getDDBDistributionByStreamStatus
* @description Method used for retrieving DynamoDB table distribution by stream status (Enabled | Disabled)
* @param {object} params CLI-parameters (For future enhancements)
* @param {object[]} tables DynamoDB tables
* @param {object} logger Logger instance
*/
export async function getDDBDistributionByStreamStatus(
params,
tables = [],
logger
) {
tables.map((t) => console.log(t));
const temp = reduceByProp(
tables,
"sana.table.StreamSpecification.StreamEnabled"
).map((cat) => {
return {
...cat,
lbl: cat.lbl ? "Enabled" : "Disabled",
};
});
const distribution = BUCKETS.map((b) => {
const bucketRow = temp.find((t) => t.lbl.toString() === b);

return {
lbl: b,
pct: bucketRow ? bucketRow.pct : 0,
count: bucketRow ? bucketRow.count : 0,
};
});

synthesizeDistribution({
title: OUTPUT_LABEL,
distribution,
array: tables,
logger,
entity: ENTITIES.DYNAMODB_TABLES,
output: params.output,
});

return distribution;
}

0 comments on commit 470aa21

Please sign in to comment.