---
policy: /ce/ca/aws/dynamodb/table-encryption
logic: /ce/ca/aws/dynamodb/table-encryption/prod.logic.yaml
executionTime: 2025-11-17T14:33:26.142012829Z
generationMs: 93
executionMs: 632
rows:
  - id: test1
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__sseDescriptionStatus__c') != 'ENABLED'
      actual: extract('CA10__sseDescriptionStatus__c') != 'ENABLED'
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test3
    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: test4
    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: {}
usedFiles:
  - path: /ce/ca/aws/dynamodb/table-encryption/policy.yaml
    md5Hash: 6C42FDE7B0B4CE6B1344A8B5FCE290A2
    content: "---\nnames:\n  full: \"AWS DynamoDB Table is not encrypted with a KMS\
      \ key\"\n  contextual: \"Table is not encrypted with a KMS key\"\ndescription:\
      \ >\n  Ensure that Amazon DynamoDB Tables are encrypted at rest using a KMS\
      \ key. By \n  default, all DynamoDB tables are encrypted with an AWS owned key.\
      \ Using a KMS \n  key (either AWS managed or Customer-Managed) provides enhanced\
      \ security through \n  centralized key management, access control, and auditing\
      \ capabilities for data \n  stored in DynamoDB.\ntype: \"COMPLIANCE_POLICY\"\
      \ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/data-encryption\"\
      \n  - \"/frameworks/aws-well-architected/sec/08/02\"\nsimilarPolicies:\n  internal:\n\
      \    - \"dec-x-c658697c\""
  - path: /ce/ca/aws/dynamodb/table-encryption/prod.logic.yaml
    md5Hash: 098F49CD063614285AC08CDE2E1A7B52
    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: "INCOMPLIANT"
          currentStateMessage: "The DynamoDB Table is not encrypted."
          remediationMessage: "Enable server-side encryption for this DynamoDB table to protect data at rest."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__sseDescriptionStatus__c"
              right:
                TEXT: "ENABLED"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The DynamoDB table is encrypted at rest."
  - path: /ce/ca/aws/dynamodb/table-encryption/test-data.json
    md5Hash: B926EB5147821C2EA4D05BF9AF16133F
    content: |-
      [
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10__sseDescriptionStatus__c') != 'ENABLED'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-29T21:59:16Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__tableStatus__c": "ACTIVE",
              "CA10__sseDescriptionStatus__c": "",
              "Id": "test1"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "300",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-29T21:59:16Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__tableStatus__c": "ACTIVE",
              "CA10__sseDescriptionStatus__c": "ENABLED",
              "Id": "test2"
          },
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-29T21:59:16Z"
              },
              "CA10__disappearanceTime__c": "2025-10-29T21:59:16Z",
              "CA10__tableStatus__c": "ACTIVE",
              "CA10__sseDescriptionStatus__c": "ENABLED",
              "Id": "test3"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__tableStatus__c') != 'ACTIVE'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-10-29T21:59:16Z"
              },
              "CA10__disappearanceTime__c": null,
              "CA10__tableStatus__c": "DELETING",
              "CA10__sseDescriptionStatus__c": "ENABLED",
              "Id": "test4"
          }
      ]
  - path: /types/CA10__CaAwsDynamoDbTable__c/object.extracts.yaml
    md5Hash: 164845CE3A8FFD533094F6278211D8F1
    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\""
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "test1",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__sseDescriptionStatus__c') != 'ENABLED'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__tableStatus__c') != 'ACTIVE'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDynamoDbTable__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__tableStatus__c STRING,
      CA10__sseDescriptionStatus__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-10-29T21:59:16Z")
    },
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__sseDescriptionStatus__c" : "",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-29T21:59:16Z")
    },
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__sseDescriptionStatus__c" : "ENABLED",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-29T21:59:16Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-10-29T21:59:16Z"),
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__sseDescriptionStatus__c" : "ENABLED",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-10-29T21:59:16Z")
    },
    "CA10__tableStatus__c" : "DELETING",
    "CA10__sseDescriptionStatus__c" : "ENABLED",
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDynamoDbTable__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__tableStatus__c STRING,
          CA10__sseDescriptionStatus__c STRING,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  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 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 extract6() { if (!this.out) { this.out = obj.CA10__sseDescriptionStatus__c; } return this.out; };
      references1.push('SSE: Status [obj.CA10__sseDescriptionStatus__c]: ' + obj.CA10__sseDescriptionStatus__c);
      if (TextLib.notEqual(extract6.call(extract6), 'ENABLED')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__sseDescriptionStatus__c') != 'ENABLED'", currentStateMessage: "The DynamoDB Table is not encrypted.", currentStateReferences: references1.join('\n'), remediation: "Enable server-side encryption for this DynamoDB table to protect data at rest.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The DynamoDB table is encrypted at rest.", 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__sseDescriptionStatus__c AS CA10__sseDescriptionStatus__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__sseDescriptionStatus__c AS CA10__sseDescriptionStatus__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDynamoDbTable__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
