---
policy: /ce/ca/aws/dynamodb/table-cost-effective-region
logic: /ce/ca/aws/dynamodb/table-cost-effective-region/prod.logic.yaml
executionTime: 2025-10-01T12:44:48.929130901Z
generationMs: 73
executionMs: 942
rows:
  - id: '001'
    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: '002'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__regionName2__c') == 'us-west-1'
      actual: extract('CA10__regionName2__c') == 'us-west-1'
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: extract('CA10__regionName2__c') == 'ca-west-1'
      actual: extract('CA10__regionName2__c') == 'ca-west-1'
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: extract('CA10__regionName2__c') == 'ap-northeast-1'
      actual: extract('CA10__regionName2__c') == 'ap-northeast-1'
    runtimeError: {}
  - id: '005'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 599
      actual: 599
    conditionText:
      expected: extract('CA10__regionName2__c') == 'ap-northeast-3'
      actual: extract('CA10__regionName2__c') == 'ap-northeast-3'
    runtimeError: {}
  - id: '006'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 699
      actual: 699
    conditionText:
      expected: extract('CA10__regionName2__c') == 'ca-central-1'
      actual: extract('CA10__regionName2__c') == 'ca-central-1'
    runtimeError: {}
  - id: '007'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 799
      actual: 799
    conditionText:
      expected: extract('CA10__regionName2__c') == 'eu-central-1'
      actual: extract('CA10__regionName2__c') == 'eu-central-1'
    runtimeError: {}
  - id: '008'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 1200
      actual: 1200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '009'
    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: '010'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 899
      actual: 899
    conditionText:
      expected: extract('CA10__regionName2__c') == 'eu-west-2'
      actual: extract('CA10__regionName2__c') == 'eu-west-2'
    runtimeError: {}
  - id: '011'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 999
      actual: 999
    conditionText:
      expected: extract('CA10__regionName2__c') == 'eu-south-1'
      actual: extract('CA10__regionName2__c') == 'eu-south-1'
    runtimeError: {}
  - id: '012'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 1099
      actual: 1099
    conditionText:
      expected: extract('CA10__regionName2__c') == 'eu-west-3'
      actual: extract('CA10__regionName2__c') == 'eu-west-3'
    runtimeError: {}
  - id: '013'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 1199
      actual: 1199
    conditionText:
      expected: extract('CA10__regionName2__c') == 'eu-central-2'
      actual: extract('CA10__regionName2__c') == 'eu-central-2'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/dynamodb/table-cost-effective-region/policy.yaml
    md5Hash: 5F3358A94AA975D9C718A5A7D736220F
    content: |
      ---
      names:
        full: AWS DynamoDB Table is located in a less cost-effective region
        contextual: Table is located in a less cost-effective region
      description: "This policy flags DynamoDB Tables that are running in AWS regions with higher pricing\
        \ and could potentially be migrated to more cost-effective regions."
      type: BEST_PRACTICE
      categories:
        - COST
      frameworkMappings:
        - "/frameworks/cloudaware/cost-efficiency-and-optimization/resource-optimization"
  - path: /ce/ca/aws/dynamodb/table-cost-effective-region/prod.logic.yaml
    md5Hash: 96ACE10170C0ABCB2924C1E7F6FFBB8F
    content: |
      ---
      inputType: "CA10__CaAwsDynamoDbTable__c"
      importExtracts:
        - file: "/types/CA10__CaAwsDynamoDbTable__c/object.extracts.yaml"
      testData:
        - file: 'test-data.json'
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The table is not active."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__tableStatus__c"
              right:
                TEXT: "ACTIVE"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in us-west-1 which is more expensive than us-west-2."
          remediationMessage: "Consider migrating the table to us-west-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "us-west-1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in ca-west-1 which is more expensive than us-west-2."
          remediationMessage: "Consider migrating the table to us-west-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "ca-west-1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in ap-northeast-1 which is more expensive than ap-northeast-2."
          remediationMessage: "Consider migrating the table to ap-northeast-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "ap-northeast-1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in ap-northeast-3 which is more expensive than ap-northeast-2."
          remediationMessage: "Consider migrating the table to ap-northeast-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "ap-northeast-3"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in ca-central-1 which is more expensive than us-east-2."
          remediationMessage: "Consider migrating the table to us-east-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "ca-central-1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in eu-central-1 which is more expensive than eu-west-1, eu-north-1, or eu-south-2."
          remediationMessage: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "eu-central-1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in eu-west-2 which is more expensive than eu-west-1, eu-north-1, or eu-south-2."
          remediationMessage: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "eu-west-2"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in eu-south-1 which is more expensive than eu-west-1, eu-north-1, or eu-south-2."
          remediationMessage: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "eu-south-1"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in eu-west-3 which is more expensive than eu-west-1, eu-north-1, or eu-south-2."
          remediationMessage: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "eu-west-3"
        - status: "INCOMPLIANT"
          currentStateMessage: "The table is running in eu-central-2 which is more expensive than eu-west-1, eu-north-1, or eu-south-2."
          remediationMessage: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2."
          check:
            IS_EQUAL:
              left:
                EXTRACT: CA10__regionName2__c
              right:
                TEXT: "eu-central-2"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The EC2 table is located in a cost-effective region."
  - path: /ce/ca/aws/dynamodb/table-cost-effective-region/test-data.json
    md5Hash: D098F85EFDDA9F53AAEF6873BCAE0E16
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "001",
          "CA10__disappearanceTime__c": "2025-07-24T00:19:37Z",
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "us-east-1"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__regionName2__c') == 'us-west-1'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "002",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "us-west-1"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "399",
            "conditionText": "extract('CA10__regionName2__c') == 'ca-west-1'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "003",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "ca-west-1"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "499",
            "conditionText": "extract('CA10__regionName2__c') == 'ap-northeast-1'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "004",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "ap-northeast-1"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "599",
            "conditionText": "extract('CA10__regionName2__c') == 'ap-northeast-3'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "005",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "ap-northeast-3"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "699",
            "conditionText": "extract('CA10__regionName2__c') == 'ca-central-1'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "006",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "ca-central-1"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "799",
            "conditionText": "extract('CA10__regionName2__c') == 'eu-central-1'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "007",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "eu-central-1"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "1200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "008",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "us-east-1"
        },
        {
          "expectedResult": {
            "status": "INAPPLICABLE",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__tableStatus__c') != 'ACTIVE'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "009",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "DELETING",
          "CA10__regionName2__c": "us-west-2"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "899",
            "conditionText": "extract('CA10__regionName2__c') == 'eu-west-2'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "010",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "eu-west-2"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "999",
            "conditionText": "extract('CA10__regionName2__c') == 'eu-south-1'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "011",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "eu-south-1"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "1099",
            "conditionText": "extract('CA10__regionName2__c') == 'eu-west-3'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "012",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "eu-west-3"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "1199",
            "conditionText": "extract('CA10__regionName2__c') == 'eu-central-2'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-07-27T15:55:37Z" },
          "Id": "013",
          "CA10__disappearanceTime__c": null,
          "CA10__tableStatus__c": "ACTIVE",
          "CA10__regionName2__c": "eu-central-2"
        }
      ]
  - path: /types/CA10__CaAwsDynamoDbTable__c/object.extracts.yaml
    md5Hash: A8D1E2741C16A4C7C104289152587E61
    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\""
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" : "001",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__regionName2__c') == 'us-west-1'",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('CA10__regionName2__c') == 'ca-west-1'",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "extract('CA10__regionName2__c') == 'ap-northeast-1'",
      "runtimeError" : null
    }
  }, {
    "Id" : "005",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "599",
      "conditionText" : "extract('CA10__regionName2__c') == 'ap-northeast-3'",
      "runtimeError" : null
    }
  }, {
    "Id" : "006",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "699",
      "conditionText" : "extract('CA10__regionName2__c') == 'ca-central-1'",
      "runtimeError" : null
    }
  }, {
    "Id" : "007",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "799",
      "conditionText" : "extract('CA10__regionName2__c') == 'eu-central-1'",
      "runtimeError" : null
    }
  }, {
    "Id" : "008",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "1200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "009",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__tableStatus__c') != 'ACTIVE'",
      "runtimeError" : null
    }
  }, {
    "Id" : "010",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "899",
      "conditionText" : "extract('CA10__regionName2__c') == 'eu-west-2'",
      "runtimeError" : null
    }
  }, {
    "Id" : "011",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "999",
      "conditionText" : "extract('CA10__regionName2__c') == 'eu-south-1'",
      "runtimeError" : null
    }
  }, {
    "Id" : "012",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "1099",
      "conditionText" : "extract('CA10__regionName2__c') == 'eu-west-3'",
      "runtimeError" : null
    }
  }, {
    "Id" : "013",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "1199",
      "conditionText" : "extract('CA10__regionName2__c') == 'eu-central-2'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsDynamoDbTable__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__tableStatus__c STRING,
      CA10__regionName2__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "001",
    "CA10__disappearanceTime__c" : new Date("2025-07-24T00:19:37Z"),
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "us-east-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "002",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "us-west-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "003",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "ca-west-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "004",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "ap-northeast-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "005",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "ap-northeast-3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "006",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "ca-central-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "007",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "eu-central-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "008",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "us-east-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "009",
    "CA10__tableStatus__c" : "DELETING",
    "CA10__regionName2__c" : "us-west-2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "010",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "eu-west-2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "011",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "eu-south-1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "012",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "eu-west-3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-07-27T15:55:37Z")
    },
    "Id" : "013",
    "CA10__tableStatus__c" : "ACTIVE",
    "CA10__regionName2__c" : "eu-central-2"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsDynamoDbTable__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__tableStatus__c STRING,
          CA10__regionName2__c 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__regionName2__c; } return this.out; };
      references1.push('Region Name [obj.CA10__regionName2__c]: ' + obj.CA10__regionName2__c);
      if (TextLib.equal(extract6.call(extract6), 'us-west-1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__regionName2__c') == 'us-west-1'", currentStateMessage: "The table is running in us-west-1 which is more expensive than us-west-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to us-west-2.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function extract9() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract9.call(extract9), 'ca-west-1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__regionName2__c') == 'ca-west-1'", currentStateMessage: "The table is running in ca-west-1 which is more expensive than us-west-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to us-west-2.", runtimeError: null};
      }
      // condition[4], conditionIndex:[400..499]
      function extract12() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract12.call(extract12), 'ap-northeast-1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 499, conditionText: "extract('CA10__regionName2__c') == 'ap-northeast-1'", currentStateMessage: "The table is running in ap-northeast-1 which is more expensive than ap-northeast-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to ap-northeast-2.", runtimeError: null};
      }
      // condition[5], conditionIndex:[500..599]
      function extract15() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract15.call(extract15), 'ap-northeast-3')) {
          return {status: 'INCOMPLIANT', conditionIndex: 599, conditionText: "extract('CA10__regionName2__c') == 'ap-northeast-3'", currentStateMessage: "The table is running in ap-northeast-3 which is more expensive than ap-northeast-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to ap-northeast-2.", runtimeError: null};
      }
      // condition[6], conditionIndex:[600..699]
      function extract18() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract18.call(extract18), 'ca-central-1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 699, conditionText: "extract('CA10__regionName2__c') == 'ca-central-1'", currentStateMessage: "The table is running in ca-central-1 which is more expensive than us-east-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to us-east-2.", runtimeError: null};
      }
      // condition[7], conditionIndex:[700..799]
      function extract21() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract21.call(extract21), 'eu-central-1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 799, conditionText: "extract('CA10__regionName2__c') == 'eu-central-1'", currentStateMessage: "The table is running in eu-central-1 which is more expensive than eu-west-1, eu-north-1, or eu-south-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2.", runtimeError: null};
      }
      // condition[8], conditionIndex:[800..899]
      function extract24() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract24.call(extract24), 'eu-west-2')) {
          return {status: 'INCOMPLIANT', conditionIndex: 899, conditionText: "extract('CA10__regionName2__c') == 'eu-west-2'", currentStateMessage: "The table is running in eu-west-2 which is more expensive than eu-west-1, eu-north-1, or eu-south-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2.", runtimeError: null};
      }
      // condition[9], conditionIndex:[900..999]
      function extract27() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract27.call(extract27), 'eu-south-1')) {
          return {status: 'INCOMPLIANT', conditionIndex: 999, conditionText: "extract('CA10__regionName2__c') == 'eu-south-1'", currentStateMessage: "The table is running in eu-south-1 which is more expensive than eu-west-1, eu-north-1, or eu-south-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2.", runtimeError: null};
      }
      // condition[10], conditionIndex:[1000..1099]
      function extract30() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract30.call(extract30), 'eu-west-3')) {
          return {status: 'INCOMPLIANT', conditionIndex: 1099, conditionText: "extract('CA10__regionName2__c') == 'eu-west-3'", currentStateMessage: "The table is running in eu-west-3 which is more expensive than eu-west-1, eu-north-1, or eu-south-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2.", runtimeError: null};
      }
      // condition[11], conditionIndex:[1100..1199]
      function extract33() { if (!this.out) { this.out = obj.CA10__regionName2__c; } return this.out; };
      if (TextLib.equal(extract33.call(extract33), 'eu-central-2')) {
          return {status: 'INCOMPLIANT', conditionIndex: 1199, conditionText: "extract('CA10__regionName2__c') == 'eu-central-2'", currentStateMessage: "The table is running in eu-central-2 which is more expensive than eu-west-1, eu-north-1, or eu-south-2.", currentStateReferences: references1.join('\n'), remediation: "Consider migrating the table to eu-west-1, eu-north-1, or eu-south-2.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 1200, conditionText: "otherwise", currentStateMessage: "The EC2 table is located in a cost-effective region.", 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.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__tableStatus__c AS CA10__tableStatus__c,
          sObject.CA10__regionName2__c AS CA10__regionName2__c,
          process_CA10__CaAwsDynamoDbTable__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__tableStatus__c AS CA10__tableStatus__c,
                  sObject.CA10__regionName2__c AS CA10__regionName2__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsDynamoDbTable__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
