--- policy: /ce/ca/aws/ec2/image-unused logic: /ce/ca/aws/ec2/image-unused/prod.logic.yaml executionTime: 2026-06-06T12:02:42.424651168Z generationMs: 70 executionMs: 1134 rows: - id: test1 match: true status: expected: DISAPPEARED actual: DISAPPEARED conditionIndex: expected: 99 actual: 99 conditionText: expected: isDisappeared(CA10__disappearanceTime__c) actual: isDisappeared(CA10__disappearanceTime__c) runtimeError: {} - id: test2 match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('CA10__state__c') != 'available' actual: extract('CA10__state__c') != 'available' runtimeError: {} - id: test3 match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 299 actual: 299 conditionText: expected: extract('CA10__creationDate__c').withinLastDays(90) actual: extract('CA10__creationDate__c').withinLastDays(90) runtimeError: {} - id: test4 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 499 actual: 499 conditionText: expected: CA10__AWS_EC2_Instances__r.has(COMPLIANT) actual: CA10__AWS_EC2_Instances__r.has(COMPLIANT) runtimeError: {} - id: test5 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 500 actual: 500 conditionText: expected: otherwise actual: otherwise runtimeError: {} - id: test6 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: extract('CA10__lastLaunchedTime__c').withinLastDays(90) actual: extract('CA10__lastLaunchedTime__c').withinLastDays(90) runtimeError: {} usedFiles: - path: /ce/ca/aws/ec2/image-unused/policy.yaml md5Hash: 7571FAD82949F1B0E804F3FC516B410D content: "---\nnames:\n full: AWS EC2 Image is unused\n contextual: Image is\ \ unused\ndescription: >\n Identify Amazon Machine Images (AMIs) that are older\ \ than 90 days and not \n associated with any running EC2 instances. Deregistering\ \ unused AMIs and \n deleting their associated snapshots can reduce storage\ \ costs.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n - \"COST\"\nframeworkMappings:\n\ \ - \"/frameworks/cloudaware/cost-efficiency-and-optimization/waste-reduction\"\ \nsimilarPolicies:\n cloudConformity:\n - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/EC2/unused-ami.html\"\ \n name: Unused AMI" - path: /ce/ca/aws/ec2/image-unused/prod.logic.yaml md5Hash: DD421AF0E2594EF35F74BA4D248347DB content: | --- inputType: "CA10__CaAwsImage__c" importExtracts: - file: "/types/CA10__CaAwsImage__c/object.extracts.yaml" testData: - file: "test-data.json" conditions: - status: "INAPPLICABLE" currentStateMessage: "The AMI is not available." check: NOT_EQUAL: left: EXTRACT: "CA10__state__c" right: TEXT: "available" - status: "INAPPLICABLE" currentStateMessage: "The AMI was created less than 90 days ago." check: IS_WITHIN_LAST_DAYS: offsetDays: 90 arg: EXTRACT: "CA10__creationDate__c" - status: "COMPLIANT" currentStateMessage: "The AMI was used within the last 90 days." check: IS_WITHIN_LAST_DAYS: offsetDays: 90 arg: EXTRACT: "CA10__lastLaunchedTime__c" - status: "COMPLIANT" currentStateMessage: "The AMI is currently in use by one or more EC2 instances." check: RELATED_LIST_HAS: status: "COMPLIANT" relationshipName: "CA10__AWS_EC2_Instances__r" otherwise: status: "INCOMPLIANT" currentStateMessage: "The AMI was not used within the last 90 days and has no associated running instances." remediationMessage: "Deregister the AMI and delete its associated EBS snapshots to reduce costs." relatedLists: - relationshipName: "CA10__AWS_EC2_Instances__r" conditions: [] otherwise: status: "COMPLIANT" currentStateMessage: "The EC2 Instance exists." - path: /ce/ca/aws/ec2/image-unused/test-data.json md5Hash: 9EBD57C188E8969733EB9111D53AA33C content: |- [ { "CA10__lastLaunchedTime__c": null, "expectedResult": { "runtimeError": null, "conditionText": "isDisappeared(CA10__disappearanceTime__c)", "conditionIndex": 99, "status": "DISAPPEARED" }, "CA10__state__c": "available", "CA10__creationDate__c": "2025-12-07T21:17:20Z", "context": { "snapshotTime": "2025-12-17T05:19:13Z" }, "CA10__AWS_EC2_Instances__r": [], "Id": "test1", "CA10__disappearanceTime__c": "2025-12-14T21:11:49Z" }, { "CA10__lastLaunchedTime__c": null, "expectedResult": { "runtimeError": null, "conditionText": "extract('CA10__state__c') != 'available'", "conditionIndex": 199, "status": "INAPPLICABLE" }, "CA10__state__c": "pending", "CA10__creationDate__c": "2025-12-17T00:10:22Z", "context": { "snapshotTime": "2025-12-17T05:19:13Z" }, "CA10__AWS_EC2_Instances__r": [], "Id": "test2", "CA10__disappearanceTime__c": null }, { "CA10__lastLaunchedTime__c": null, "expectedResult": { "runtimeError": null, "conditionText": "extract('CA10__creationDate__c').withinLastDays(90)", "conditionIndex": 299, "status": "INAPPLICABLE" }, "CA10__state__c": "available", "CA10__creationDate__c": "2025-12-14T08:11:20Z", "context": { "snapshotTime": "2025-12-17T05:19:13Z" }, "CA10__AWS_EC2_Instances__r": [], "Id": "test3", "CA10__disappearanceTime__c": null }, { "CA10__lastLaunchedTime__c": "2021-09-23T00:09:39Z", "expectedResult": { "runtimeError": null, "conditionText": "CA10__AWS_EC2_Instances__r.has(COMPLIANT)", "conditionIndex": 499, "status": "COMPLIANT" }, "CA10__state__c": "available", "CA10__creationDate__c": "2021-09-23T00:09:39Z", "context": { "snapshotTime": "2025-12-17T05:19:13Z" }, "CA10__AWS_EC2_Instances__r": [ { "CA10__image__c": "test4", "Id": "test4_1", "CA10__disappearanceTime__c": null } ], "Id": "test4", "CA10__disappearanceTime__c": null }, { "CA10__lastLaunchedTime__c": null, "expectedResult": { "runtimeError": null, "conditionText": "otherwise", "conditionIndex": 500, "status": "INCOMPLIANT" }, "CA10__state__c": "available", "CA10__creationDate__c": "2025-08-09T12:27:22Z", "context": { "snapshotTime": "2025-12-17T05:19:13Z" }, "CA10__AWS_EC2_Instances__r": [], "Id": "test5", "CA10__disappearanceTime__c": null }, { "CA10__lastLaunchedTime__c": "2025-12-17T05:19:13Z", "expectedResult": { "runtimeError": null, "conditionText": "extract('CA10__lastLaunchedTime__c').withinLastDays(90)", "conditionIndex": 399, "status": "COMPLIANT" }, "CA10__state__c": "available", "CA10__creationDate__c": "2025-08-09T12:27:22Z", "context": { "snapshotTime": "2025-12-17T05:19:13Z" }, "CA10__AWS_EC2_Instances__r": [], "Id": "test6", "CA10__disappearanceTime__c": null } ] - path: /types/CA10__CaAwsImage__c/object.extracts.yaml md5Hash: C8CCEBD443D124E5F81FD189F4E6E404 content: "---\nextracts:\n# Nulable. Boolean. Values: true, false.\n - name:\ \ \"CA10__public__c\"\n value: \n FIELD:\n path: \"CA10__public__c\"\ \n# Values: pending | available | invalid | deregistered | transient | failed\ \ | error | disabled. \n# Not nullable\n - name: \"CA10__state__c\"\n value:\ \ \n FIELD:\n path: \"CA10__state__c\"\n#Not nullable\n - name:\ \ \"CA10__creationDate__c\"\n value: \n FIELD:\n path: \"CA10__creationDate__c\"\ \n# Nullable\n - name: \"CA10__lastLaunchedTime__c\"\n value: \n FIELD:\n\ \ path: \"CA10__lastLaunchedTime__c\"\n" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "test1", "expectedResult" : { "runtimeError" : null, "conditionText" : "isDisappeared(CA10__disappearanceTime__c)", "conditionIndex" : 99, "status" : "DISAPPEARED" } }, { "Id" : "test2", "expectedResult" : { "runtimeError" : null, "conditionText" : "extract('CA10__state__c') != 'available'", "conditionIndex" : 199, "status" : "INAPPLICABLE" } }, { "Id" : "test3", "expectedResult" : { "runtimeError" : null, "conditionText" : "extract('CA10__creationDate__c').withinLastDays(90)", "conditionIndex" : 299, "status" : "INAPPLICABLE" } }, { "Id" : "test4", "expectedResult" : { "runtimeError" : null, "conditionText" : "CA10__AWS_EC2_Instances__r.has(COMPLIANT)", "conditionIndex" : 499, "status" : "COMPLIANT" } }, { "Id" : "test5", "expectedResult" : { "runtimeError" : null, "conditionText" : "otherwise", "conditionIndex" : 500, "status" : "INCOMPLIANT" } }, { "Id" : "test6", "expectedResult" : { "runtimeError" : null, "conditionText" : "extract('CA10__lastLaunchedTime__c').withinLastDays(90)", "conditionIndex" : 399, "status" : "COMPLIANT" } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsImage__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-12-17T05:19:13Z") }, "CA10__disappearanceTime__c" : new Date("2025-12-14T21:11:49Z"), "CA10__state__c" : "available", "CA10__creationDate__c" : new Date("2025-12-07T21:17:20Z"), "Id" : "test1" }, { "context" : { "snapshotTime" : new Date("2025-12-17T05:19:13Z") }, "CA10__state__c" : "pending", "CA10__creationDate__c" : new Date("2025-12-17T00:10:22Z"), "Id" : "test2" }, { "context" : { "snapshotTime" : new Date("2025-12-17T05:19:13Z") }, "CA10__state__c" : "available", "CA10__creationDate__c" : new Date("2025-12-14T08:11:20Z"), "Id" : "test3" }, { "context" : { "snapshotTime" : new Date("2025-12-17T05:19:13Z") }, "CA10__state__c" : "available", "CA10__creationDate__c" : new Date("2021-09-23T00:09:39Z"), "CA10__lastLaunchedTime__c" : new Date("2021-09-23T00:09:39Z"), "Id" : "test4" }, { "context" : { "snapshotTime" : new Date("2025-12-17T05:19:13Z") }, "CA10__state__c" : "available", "CA10__creationDate__c" : new Date("2025-08-09T12:27:22Z"), "Id" : "test5" }, { "context" : { "snapshotTime" : new Date("2025-12-17T05:19:13Z") }, "CA10__state__c" : "available", "CA10__creationDate__c" : new Date("2025-08-09T12:27:22Z"), "CA10__lastLaunchedTime__c" : new Date("2025-12-17T05:19:13Z"), "Id" : "test6" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsInstance__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2025-12-17T05:19:13Z") }, "CA10__image__c" : "test4", "Id" : "test4_1" } ]; """; CREATE TEMP FUNCTION process_CA10__CaAwsImage__c( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__state__c STRING, CA10__creationDate__c TIMESTAMP, CA10__lastLaunchedTime__c TIMESTAMP, CA10__AWS_EC2_Instances__r ARRAY >>, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" 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 todayMinus90Day = new Date(snapshotTime.toISOString().substr(0,10)+'T00:00:00.000Z').getTime() + (-90 * 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__state__c; } return this.out; }; references1.push('State [obj.CA10__state__c]: ' + obj.CA10__state__c); if (TextLib.notEqual(extract3.call(extract3), 'available')) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__state__c') != 'available'", currentStateMessage: "The AMI is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[2], conditionIndex:[200..299] function extract6() { if (!this.out) { this.out = obj.CA10__creationDate__c; } return this.out; }; references1.push('Creation Date [obj.CA10__creationDate__c]: ' + obj.CA10__creationDate__c); if (extract6.call(extract6) != null && extract6.call(extract6).getTime() >= todayMinus90Day && extract6.call(extract6).getTime() < todayPlus1Day) { return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "extract('CA10__creationDate__c').withinLastDays(90)", currentStateMessage: "The AMI was created less than 90 days ago.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[3], conditionIndex:[300..399] function extract10() { if (!this.out) { this.out = obj.CA10__lastLaunchedTime__c; } return this.out; }; references1.push('Last Launched Time [obj.CA10__lastLaunchedTime__c]: ' + obj.CA10__lastLaunchedTime__c); if (extract10.call(extract10) != null && extract10.call(extract10).getTime() >= todayMinus90Day && extract10.call(extract10).getTime() < todayPlus1Day) { return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__lastLaunchedTime__c').withinLastDays(90)", currentStateMessage: "The AMI was used within the last 90 days.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } var count_CA10__AWS_EC2_Instances__r_COMPLIANT13 = 0; if (obj.CA10__AWS_EC2_Instances__r != null) { for (var i14 = 0; i14 < obj.CA10__AWS_EC2_Instances__r.length; i14++) { if (typeof(obj.CA10__AWS_EC2_Instances__r[i14].status) !== 'undefined') { if (obj.CA10__AWS_EC2_Instances__r[i14].status == 'COMPLIANT') { count_CA10__AWS_EC2_Instances__r_COMPLIANT13 += obj.CA10__AWS_EC2_Instances__r[i14].count; } } else { if (obj.CA10__AWS_EC2_Instances__r[i14].result.status == 'COMPLIANT') { count_CA10__AWS_EC2_Instances__r_COMPLIANT13 += 1; } } } } // condition[4], conditionIndex:[400..499] references1.push('Related list [CA10__AWS_EC2_Instances__r] ' + (count_CA10__AWS_EC2_Instances__r_COMPLIANT13 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status'); if (count_CA10__AWS_EC2_Instances__r_COMPLIANT13 > 0) { return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "CA10__AWS_EC2_Instances__r.has(COMPLIANT)", currentStateMessage: "The AMI is currently in use by one or more EC2 instances.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } return {status: 'INCOMPLIANT', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "The AMI was not used within the last 90 days and has no associated running instances.", currentStateReferences: references1.join('\n'), remediation: "Deregister the AMI and delete its associated EBS snapshots to reduce costs.", runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10__AWS_EC2_Instances__r( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__image__c STRING, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" 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}; } return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "The EC2 Instance exists.", 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__state__c AS CA10__state__c, sObject.CA10__creationDate__c AS CA10__creationDate__c, sObject.CA10__lastLaunchedTime__c AS CA10__lastLaunchedTime__c, `CA10__AWS_EC2_Instances__r`.arr AS CA10__AWS_EC2_Instances__r, sObject.Id AS Id, process_CA10__CaAwsImage__c( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__state__c AS CA10__state__c, sObject.CA10__creationDate__c AS CA10__creationDate__c, sObject.CA10__lastLaunchedTime__c AS CA10__lastLaunchedTime__c, `CA10__AWS_EC2_Instances__r`.arr AS CA10__AWS_EC2_Instances__r, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaAwsImage__c()) AS sObject LEFT JOIN ( SELECT sObject.CA10__image__c, ARRAY_AGG( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__image__c AS CA10__image__c, sObject.Id AS Id, process_CA10__AWS_EC2_Instances__r( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__image__c AS CA10__image__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10__CaAwsInstance__c()) AS sObject GROUP BY sObject.CA10__image__c ) AS `CA10__AWS_EC2_Instances__r` ON sObject.Id = `CA10__AWS_EC2_Instances__r`.CA10__image__c ) sObject ON sObject.Id = expectedResult.Id;