--- policy: /ce/ca/aws/dynamodb/table-unused logic: /ce/ca/aws/dynamodb/table-unused/prod.logic.yaml executionTime: 2026-06-06T12:02:40.454678667Z generationMs: 58 executionMs: 1663 rows: - id: '001' match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('CA10__tableStatus__c') != 'ACTIVE' actual: extract('CA10__tableStatus__c') != 'ACTIVE' runtimeError: {} - id: '002' match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 299 actual: 299 conditionText: expected: extract('CA10__creationDateTime__c').withinLastDays(30) actual: extract('CA10__creationDateTime__c').withinLastDays(30) runtimeError: {} - id: '003' match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: extract('CA10__itemCount__c') == number(0.0) actual: extract('CA10__itemCount__c') == number(0.0) runtimeError: {} - id: '004' match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 400 actual: 400 conditionText: expected: otherwise actual: otherwise runtimeError: {} usedFiles: - path: /ce/ca/aws/dynamodb/table-unused/policy.yaml md5Hash: B5979C3E4755A572EADD36F7A82BB076 content: "---\nnames:\n full: \"AWS DynamoDB Table is unused\"\n contextual:\ \ \"Table is unused\"\ndescription: >\n Identify AWS DynamoDB Tables that appear\ \ to be unused (empty). A table is \n considered unused if it has been active\ \ for more than 30 days but contains \n zero items. Removing unused tables\ \ helps reduce storage costs and clutter.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\ \ - \"COST\"\nframeworkMappings:\n - \"/frameworks/cloudaware/cost-efficiency-and-optimization/waste-reduction\"\ \n - \"/frameworks/aws-well-architected/cost/04/02\"\nsimilarPolicies:\n cloudConformity:\n\ \ - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/DynamoDB/unused-dynamodb-tables.html\n\ \ name: Unused Table" - path: /ce/ca/aws/dynamodb/table-unused/prod.logic.yaml md5Hash: D63425333F5F756DF790335FB0F2E184 content: | inputType: "CA10__CaAwsDynamoDbTable__c" testData: - file: "test-data.json" importExtracts: - file: /types/CA10__CaAwsDynamoDbTable__c/object.extracts.yaml conditions: - status: "INAPPLICABLE" currentStateMessage: "The table is not active." check: NOT_EQUAL: left: EXTRACT: "CA10__tableStatus__c" right: TEXT: "ACTIVE" - status: "INAPPLICABLE" currentStateMessage: "The table was created less than 30 days ago." check: IS_WITHIN_LAST_DAYS: offsetDays: 30 arg: EXTRACT: "CA10__creationDateTime__c" - status: "INCOMPLIANT" currentStateMessage: "The DynamoDB table is unused and contains 0 items." remediationMessage: "Delete the table." check: IS_EQUAL: left: EXTRACT: "CA10__itemCount__c" right: NUMBER: 0.0 otherwise: status: "COMPLIANT" currentStateMessage: "The table contains items and is considered in use." - path: /ce/ca/aws/dynamodb/table-unused/test-data.json md5Hash: 98DFD05FF2ED1570423D71D87B621A3E content: | [ { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "199", "conditionText": "extract('CA10__tableStatus__c') != 'ACTIVE'", "runtimeError": null }, "context": { "snapshotTime": "2025-12-02T01:10:46Z" }, "CA10__disappearanceTime__c": null, "CA10__tableStatus__c": "INACTIVE", "CA10__creationDateTime__c": "2024-12-02T01:10:46Z", "CA10__itemCount__c": null, "Id": "001" }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "299", "conditionText": "extract('CA10__creationDateTime__c').withinLastDays(30)", "runtimeError": null }, "context": { "snapshotTime": "2025-12-02T01:10:46Z" }, "CA10__disappearanceTime__c": null, "CA10__tableStatus__c": "ACTIVE", "CA10__creationDateTime__c": "2025-11-02T01:10:46Z", "CA10__itemCount__c": 0, "Id": "002" }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "399", "conditionText": "extract('CA10__itemCount__c') == number(0.0)", "runtimeError": null }, "context": { "snapshotTime": "2025-12-02T01:10:46Z" }, "CA10__disappearanceTime__c": null, "CA10__tableStatus__c": "ACTIVE", "CA10__creationDateTime__c": "2024-12-02T01:10:46Z", "CA10__itemCount__c": 0, "Id": "003" }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "400", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2025-12-02T01:10:46Z" }, "CA10__disappearanceTime__c": null, "CA10__tableStatus__c": "ACTIVE", "CA10__creationDateTime__c": "2024-12-02T01:10:46Z", "CA10__itemCount__c": 7, "Id": "004" } ] - path: /types/CA10__CaAwsDynamoDbTable__c/object.extracts.yaml md5Hash: EC959FF9A6572890388AA7C1C47122EF content: "---\nextracts:\n# Nullable, null is equal to PROVISIONED\n - name:\ \ \"CA10__billingMode__c\"\n value:\n FIELD:\n path: CA10__billingMode__c\n\ \ # undeterminedIf:\n # noAccessDelegate:\n # path:\ \ \"CA10__billingMode__c\"\n # currentStateMessage: \"Unable to determine\ \ Table Billing Mode. Possible permission issue with dynamodb:DescribeTable.\"\ \n# Values: ENABLED | DISABLED. Not nullable. \n - name: \"CA10__pointInTimeRecoveryStatus__c\"\ \n value:\n FIELD:\n path: CA10__pointInTimeRecoveryStatus__c\n\ \ # undeterminedIf:\n # noAccessDelegate:\n # path:\ \ \"CA10__pointInTimeRecoveryStatus__c\"\n # currentStateMessage:\ \ \"Unable to determine Point In Time Recovery Status. Possible permission issue\ \ with dynamodb:DescribeTable.\"\n# Nullable.\n - name: \"CA10__regionName2__c\"\ \n value:\n FIELD:\n path: \"CA10__regionName2__c\"\n# Values:\ \ CREATING | UPDATING | DELETING | ACTIVE | INACCESSIBLE_ENCRYPTION_CREDENTIALS\ \ | \n# ARCHIVING | ARCHIVED | REPLICATION_NOT_AUTHORIZED\n# Not nullable. Possible\ \ permission issue with dynamodb:DescribeTable.\n - name: \"CA10__tableStatus__c\"\ \n value:\n FIELD:\n path: \"CA10__tableStatus__c\"\n# Values:\ \ ENABLED | null. Possible permission issue with dynamodb:DescribeTable.\n \ \ - name: \"CA10__sseDescriptionStatus__c\"\n value:\n FIELD:\n \ \ path: \"CA10__sseDescriptionStatus__c\"\n# Not nullable. Number\n - name:\ \ \"CA10__itemCount__c\"\n value:\n FIELD:\n path: \"CA10__itemCount__c\"\ \n undeterminedIf:\n noAccessDelegate:\n path: \"\ CA10__itemCount__c\"\n currentStateMessage: \"Dynamo DB Table item\ \ count cannot be empty. Possible permission issue with dynamodb:DescribeTable\"\ \n# Not nullable.\n - name: \"CA10__creationDateTime__c\"\n value:\n \ \ FIELD:\n path: \"CA10__creationDateTime__c\"\n undeterminedIf:\n\ \ noAccessDelegate:\n path: \"CA10__creationDateTime__c\"\ \n currentStateMessage: \"Dynamo DB Table creation date cannot be\ \ empty. Possible permission issue with dynamodb:DescribeTable\"\n" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "001", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "199", "conditionText" : "extract('CA10__tableStatus__c') != 'ACTIVE'", "runtimeError" : null } }, { "Id" : "002", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "299", "conditionText" : "extract('CA10__creationDateTime__c').withinLastDays(30)", "runtimeError" : null } }, { "Id" : "003", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "399", "conditionText" : "extract('CA10__itemCount__c') == number(0.0)", "runtimeError" : null } }, { "Id" : "004", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "400", "conditionText" : "otherwise", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsDynamoDbTable__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-12-02T01:10:46Z") }, "CA10__tableStatus__c" : "INACTIVE", "CA10__creationDateTime__c" : new Date("2024-12-02T01:10:46Z"), "CA10__itemCount__c" : null, "Id" : "001" }, { "context" : { "snapshotTime" : new Date("2025-12-02T01:10:46Z") }, "CA10__tableStatus__c" : "ACTIVE", "CA10__creationDateTime__c" : new Date("2025-11-02T01:10:46Z"), "CA10__itemCount__c" : 0, "Id" : "002" }, { "context" : { "snapshotTime" : new Date("2025-12-02T01:10:46Z") }, "CA10__tableStatus__c" : "ACTIVE", "CA10__creationDateTime__c" : new Date("2024-12-02T01:10:46Z"), "CA10__itemCount__c" : 0, "Id" : "003" }, { "context" : { "snapshotTime" : new Date("2025-12-02T01:10:46Z") }, "CA10__tableStatus__c" : "ACTIVE", "CA10__creationDateTime__c" : new Date("2024-12-02T01:10:46Z"), "CA10__itemCount__c" : 7, "Id" : "004" } ]; """; CREATE TEMP FUNCTION process_CA10__CaAwsDynamoDbTable__c( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__tableStatus__c STRING, CA10__creationDateTime__c TIMESTAMP, CA10__itemCount__c FLOAT64, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var IsEmptyLib = new function () { this.simpleIsEmpty = function(arg) { return arg == null; }; this.simpleIsNotEmpty = function(arg) { return arg != null; }; }(); var TextLib = new function () { this.normalize = function(arg) { return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase(); }; this.isEmpty = function(arg) { return this.normalize(arg) == ''; }; this.isNotEmpty = function(arg) { return this.normalize(arg) != ''; }; this.equal = function(left, right) { return this.normalize(left) == this.normalize(right); }; this.notEqual = function(left, right) { return this.normalize(left) != this.normalize(right); }; this.startsWith = function(arg, substring) { return this.normalize(arg).startsWith(this.normalize(substring)); }; this.endsWith = function(arg, substring) { return this.normalize(arg).endsWith(this.normalize(substring)); }; this.contains = function(arg, substring) { return this.normalize(arg).includes(this.normalize(substring)); }; this.containsAll = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.every(sub => normalizedArg.includes(this.normalize(sub))); }; this.containsAny = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.some(sub => normalizedArg.includes(this.normalize(sub))); }; }(); var todayMinus30Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (-30 * 86400000); var todayPlus1Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (1 * 86400000); var references1 = []; // condition[0], conditionIndex:[0..99] references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c); if (obj.CA10__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[1], conditionIndex:[100..199] function extract3() { if (!this.out) { this.out = obj.CA10__tableStatus__c; } return this.out; }; references1.push('Table Status [obj.CA10__tableStatus__c]: ' + obj.CA10__tableStatus__c); if (TextLib.notEqual(extract3.call(extract3), 'ACTIVE')) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__tableStatus__c') != 'ACTIVE'", currentStateMessage: "The table is not active.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[2], conditionIndex:[200..299] function fieldChecked7() { if (IsEmptyLib.simpleIsEmpty(obj.CA10__creationDateTime__c)) { throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10__creationDateTime__c.delegatedTo(CA10__creationDateTime__c).isEmpty()", currentStateMessage: "Dynamo DB Table creation date cannot be empty. Possible permission issue with dynamodb:DescribeTable", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__creationDateTime__c; } function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; }; references1.push('Creation Date Time [obj.CA10__creationDateTime__c]: ' + obj.CA10__creationDateTime__c); try { if (extract6.call(extract6) != null && extract6.call(extract6).getTime() >= todayMinus30Day && extract6.call(extract6).getTime() < todayPlus1Day) { return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__creationDateTime__c').withinLastDays(30)", currentStateMessage: "The table was created less than 30 days ago.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } // condition[3], conditionIndex:[300..399] function fieldChecked11() { if (IsEmptyLib.simpleIsEmpty(obj.CA10__itemCount__c)) { throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10__itemCount__c.delegatedTo(CA10__itemCount__c).isEmpty()", currentStateMessage: "Dynamo DB Table item count cannot be empty. Possible permission issue with dynamodb:DescribeTable", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__itemCount__c; } function extract10() { if (!this.out) { this.out = fieldChecked11(); } return this.out; }; references1.push('Item Count [obj.CA10__itemCount__c]: ' + obj.CA10__itemCount__c); try { if (extract10.call(extract10) == 0.0) { return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__itemCount__c') == number(0.0)", currentStateMessage: "The DynamoDB table is unused and contains 0 items.", currentStateReferences: references1.join('\n'), remediation: "Delete the table.", runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "The table contains items and is considered in use.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; SELECT expectedResult.Id as Id, IF ( IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '') AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1) AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '') AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''), "MATCH", "FAIL" ) as match, expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus, expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex, expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText, expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError FROM UNNEST(mock_ExpectedResult()) expectedResult LEFT JOIN ( SELECT sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__tableStatus__c AS CA10__tableStatus__c, sObject.CA10__creationDateTime__c AS CA10__creationDateTime__c, sObject.CA10__itemCount__c AS CA10__itemCount__c, sObject.Id AS Id, process_CA10__CaAwsDynamoDbTable__c( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__tableStatus__c AS CA10__tableStatus__c, sObject.CA10__creationDateTime__c AS CA10__creationDateTime__c, sObject.CA10__itemCount__c AS CA10__itemCount__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaAwsDynamoDbTable__c()) AS sObject ) sObject ON sObject.Id = expectedResult.Id;