---
policy: /ce/ca/aws/sagemaker/endpoint-instance-count
logic: /ce/ca/aws/sagemaker/endpoint-instance-count/prod.logic.yaml
executionTime: 2026-01-24T12:02:26.439701062Z
generationMs: 62
executionMs: 649
rows:
  - id: test1
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10A1__status__c') != 'InService'
      actual: extract('CA10A1__status__c') != 'InService'
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount\
        \ < `2`])') > number(0.0)"
      actual: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount\
        \ < `2`])') > number(0.0)"
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: isEmptyLookup('CA10A1__endpointConfig__r')
      actual: isEmptyLookup('CA10A1__endpointConfig__r')
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 500
      actual: 500
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 304
      actual: 304
    conditionText:
      expected: CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()
      actual: CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()
    runtimeError: {}
  - id: test6
    match: true
    status:
      expected: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 304
      actual: 304
    conditionText:
      expected: CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()
      actual: CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()
    runtimeError: {}
  - id: test7
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 499
      actual: 499
    conditionText:
      expected: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount\
        \ > `1`])') > number(0.0)"
      actual: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount\
        \ > `1`])') > number(0.0)"
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/sagemaker/endpoint-instance-count/policy.yaml
    md5Hash: 5122F1CB7CD54E5BF9DA79CE77FDA4FF
    content: "---\nnames:\n  full: \"AWS SageMaker Endpoint has less than 2 instances\"\
      \n  contextual: \"Endpoint has less than 2 instances\"\ndescription: >\n  Ensure\
      \ that AWS SageMaker endpoints are configured with at least two instances. \n\
      \  A multi-instance deployment provides higher availability and resilience by\
      \ ensuring \n  that traffic can be served even if an individual instance or\
      \ Availability Zone fails.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"\
      RELIABILITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/system-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/sagemaker/04\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[SageMaker.4] SageMaker endpoint production variants should have\
      \ an initial instance count greater than 1\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/sagemaker-controls.html#sagemaker-4\""
  - path: /ce/ca/aws/sagemaker/endpoint-instance-count/prod.logic.yaml
    md5Hash: DAFB1379E318D4D93521C41327C5E763
    content: |-
      ---
      inputType: "CA10A1__CaAwsSageMakerEndpoint__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10A1__CaAwsSageMakerEndpoint__c/object.extracts.yaml"
        - file: "/types/CA10A1__CaAwsSageMakerEndpointConfig__c/object.extracts.yaml"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The SageMaker Endpoint is not in service."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10A1__status__c"
              right:
                TEXT: "InService"
        - status: "UNDETERMINED"
          currentStateMessage: "The Endpoint Configuration or its production variants are not present in the CMDB."
          check:
            IS_EMPTY_LOOKUP: "CA10A1__endpointConfig__r"
        - status: "INCOMPLIANT"
          currentStateMessage: "At least one production variant in the endpoint configuration has an instance count less than 2."
          remediationMessage: "Increase the instance count for all production variants to at least 2."
          check:
            # Evaluates the JSON array of variants to see if any have initialInstanceCount < 2
            GREATER_THAN:
              left:
                JSON_QUERY_NUMBER:
                  arg:
                    EXTRACT: "caJsonFrom__productionVariantsJson__c"
                  expression: "length([?initialInstanceCount < `2`])"
                  undeterminedIf:
                    evaluationError: "Failed to query the production variants JSON."
                    resultTypeMismatch: "Query did not return a number."
              right:
                NUMBER: 0
        - status: "COMPLIANT"
          currentStateMessage: "All production variants for this endpoint have at least two instances configured."
          check:
            # Evaluates the JSON array of variants to see if any have initialInstanceCount > 1
            GREATER_THAN:
              left:
                JSON_QUERY_NUMBER:
                  arg:
                    EXTRACT: "caJsonFrom__productionVariantsJson__c"
                  expression: "length([?initialInstanceCount > `1`])"
                  undeterminedIf:
                    evaluationError: "Failed to query the production variants JSON."
                    resultTypeMismatch: "Query did not return a number."
              right:
                NUMBER: 0
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unable to determine the initial instance count of the Endpoint Config."
  - path: /ce/ca/aws/sagemaker/endpoint-instance-count/test-data.json
    md5Hash: 98698444856473108388629ABB153214
    content: |-
      [
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10A1__status__c') != 'InService'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "Failed",
              "CA10A1__endpointConfig__c": null,
              "CA10A1__endpointConfigArn__c": "endpointConfigArn1",
              "Id": "test1",
              "CA10A1__endpointConfig__r": {
                  "Id": null,
                  "CA10A1__disappearanceTime__c": null,
                  "CA10A1__productionVariantsJson__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount < `2`])') > number(0.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "InService",
              "CA10A1__endpointConfig__c": "test2_1",
              "CA10A1__endpointConfigArn__c": "endpointConfigArn2",
              "Id": "test2",
              "CA10A1__endpointConfig__r": {
                  "Id": "test2_1",
                  "CA10A1__disappearanceTime__c": null,
                  "CA10A1__productionVariantsJson__c": "[{\"variantName\":\"AllTraffic\",\"modelName\":\"modelName\",\"initialInstanceCount\":1,\"instanceType\":\"ml.g5.2xlarge\",\"initialVariantWeight\":1.0,\"modelDataDownloadTimeoutInSeconds\":3600,\"containerStartupHealthCheckTimeoutInSeconds\":3600}]"
              }
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "299",
                  "conditionText": "isEmptyLookup('CA10A1__endpointConfig__r')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "InService",
              "CA10A1__endpointConfig__c": "",
              "CA10A1__endpointConfigArn__c": "endpointConfigArn3",
              "Id": "test3",
              "CA10A1__endpointConfig__r": {
                  "Id": null,
                  "CA10A1__disappearanceTime__c": null,
                  "CA10A1__productionVariantsJson__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "500",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "InService",
              "CA10A1__endpointConfig__c": "test4_1",
              "CA10A1__endpointConfigArn__c": "endpointConfigArn2",
              "Id": "test4",
              "CA10A1__endpointConfig__r": {
                  "Id": "test4_1",
                  "CA10A1__disappearanceTime__c": null,
                  "CA10A1__productionVariantsJson__c": "[]"
              }
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "304",
                  "conditionText": "CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "InService",
              "CA10A1__endpointConfig__c": "test5_1",
              "CA10A1__endpointConfigArn__c": "endpointConfigArn2",
              "Id": "test5",
              "CA10A1__endpointConfig__r": {
                  "Id": "test5_1",
                  "CA10A1__disappearanceTime__c": null,
                  "CA10A1__productionVariantsJson__c": ""
              }
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "304",
                  "conditionText": "CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "InService",
              "CA10A1__endpointConfig__c": "test6_1",
              "CA10A1__endpointConfigArn__c": "endpointConfigArn2",
              "Id": "test6",
              "CA10A1__endpointConfig__r": {
                  "Id": "test6_1",
                  "CA10A1__disappearanceTime__c": null,
                  "CA10A1__productionVariantsJson__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "499",
                  "conditionText": "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount > `1`])') > number(0.0)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "InService",
              "CA10A1__endpointConfig__c": "test7_1",
              "CA10A1__endpointConfigArn__c": "endpointConfigArn2",
              "Id": "test7",
              "CA10A1__endpointConfig__r": {
                  "Id": "test7_1",
                  "CA10A1__disappearanceTime__c": null,
                  "CA10A1__productionVariantsJson__c": "[{\"variantName\":\"AllTraffic\",\"modelName\":\"modelName\",\"initialInstanceCount\":3,\"instanceType\":\"ml.g5.2xlarge\",\"initialVariantWeight\":1.0,\"modelDataDownloadTimeoutInSeconds\":3600,\"containerStartupHealthCheckTimeoutInSeconds\":3600}]"
              }
          }
      ]
  - path: /types/CA10A1__CaAwsSageMakerEndpoint__c/object.extracts.yaml
    md5Hash: 6FEF5F0D1482FCEDF426200AE2C8E910
    content: "---\nextracts:\n# InService | OutOfService | Creating | Updating | SystemUpdating\
      \ | RollingBack | Deleting | Failed | UpdateRollbackFailed.\n# Not nullable.\
      \ Can't have no access, retrieved via sagemaker:ListEndpoints\n  - name: CA10A1__status__c\n\
      \    value:\n      FIELD: \n        path: CA10A1__status__c\n"
  - path: /types/CA10A1__CaAwsSageMakerEndpointConfig__c/object.extracts.yaml
    md5Hash: C98A8ED84E6D2328252FC7FA00A80C30
    content: "---\nextracts:\n# Nullable.\n  - name: CA10A1__kmsKeyId__c\n    value:\n\
      \      FIELD: \n        path: CA10A1__kmsKeyId__c\n# Not nullable.\n  - name:\
      \ CA10A1__productionVariantsJson__c\n    value:\n      FIELD: \n        path:\
      \ CA10A1__productionVariantsJson__c\n        undeterminedIf:\n          noAccessDelegate:\n\
      \            path: \"CA10A1__productionVariantsJson__c\"\n            currentStateMessage:\
      \ \"Endpoint Config Production Variants cannot be empty. Possible permission\
      \ issue with sagemaker:DescribeEndpointConfig\"\n  - name: caJsonFrom__productionVariantsJson__c\n\
      \    value:\n      JSON_FROM:\n        arg:\n          EXTRACT: \"CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c\"\
      \n        undeterminedIf:\n          isEmpty: \"Endpoint Config Production Variants\
      \ cannot be empty. Possible permission issue with sagemaker:DescribeEndpointConfig\"\
      \n          isInvalid: \"The Production Variants JSON is invalid.\""
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" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10A1__status__c') != 'InService'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount < `2`])') > number(0.0)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "299",
      "conditionText" : "isEmptyLookup('CA10A1__endpointConfig__r')",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "500",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "304",
      "conditionText" : "CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test6",
    "expectedResult" : {
      "status" : "UNDETERMINED",
      "conditionIndex" : "304",
      "conditionText" : "CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test7",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "499",
      "conditionText" : "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount > `1`])') > number(0.0)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsSageMakerEndpoint__c()
  RETURNS ARRAY<STRUCT<
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__status__c STRING,
      CA10A1__endpointConfig__c STRING,
      CA10A1__endpointConfigArn__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "Failed",
    "CA10A1__endpointConfig__c" : null,
    "CA10A1__endpointConfigArn__c" : "endpointConfigArn1",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "InService",
    "CA10A1__endpointConfig__c" : "test2_1",
    "CA10A1__endpointConfigArn__c" : "endpointConfigArn2",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "InService",
    "CA10A1__endpointConfig__c" : "",
    "CA10A1__endpointConfigArn__c" : "endpointConfigArn3",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "InService",
    "CA10A1__endpointConfig__c" : "test4_1",
    "CA10A1__endpointConfigArn__c" : "endpointConfigArn2",
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "InService",
    "CA10A1__endpointConfig__c" : "test5_1",
    "CA10A1__endpointConfigArn__c" : "endpointConfigArn2",
    "Id" : "test5"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "InService",
    "CA10A1__endpointConfig__c" : "test6_1",
    "CA10A1__endpointConfigArn__c" : "endpointConfigArn2",
    "Id" : "test6"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "InService",
    "CA10A1__endpointConfig__c" : "test7_1",
    "CA10A1__endpointConfigArn__c" : "endpointConfigArn2",
    "Id" : "test7"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsSageMakerEndpointConfig__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__productionVariantsJson__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : null,
    "CA10A1__productionVariantsJson__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : "test2_1",
    "CA10A1__productionVariantsJson__c" : "[{\"variantName\":\"AllTraffic\",\"modelName\":\"modelName\",\"initialInstanceCount\":1,\"instanceType\":\"ml.g5.2xlarge\",\"initialVariantWeight\":1.0,\"modelDataDownloadTimeoutInSeconds\":3600,\"containerStartupHealthCheckTimeoutInSeconds\":3600}]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : "test4_1",
    "CA10A1__productionVariantsJson__c" : "[]"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : "test5_1",
    "CA10A1__productionVariantsJson__c" : ""
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : "test6_1",
    "CA10A1__productionVariantsJson__c" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : "test7_1",
    "CA10A1__productionVariantsJson__c" : "[{\"variantName\":\"AllTraffic\",\"modelName\":\"modelName\",\"initialInstanceCount\":3,\"instanceType\":\"ml.g5.2xlarge\",\"initialVariantWeight\":1.0,\"modelDataDownloadTimeoutInSeconds\":3600,\"containerStartupHealthCheckTimeoutInSeconds\":3600}]"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A1__CaAwsSageMakerEndpoint__c(
      obj STRUCT<
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__status__c STRING,
          CA10A1__endpointConfig__c STRING,
          CA10A1__endpointConfigArn__c STRING,
          Id STRING,
          CA10A1__endpointConfig__r STRUCT<
              Id STRING,
              CA10A1__disappearanceTime__c TIMESTAMP,
              CA10A1__productionVariantsJson__c STRING
          >
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  OPTIONS (library=['gs://compliance-platform-public/jmespath.min.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 BytesLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg;
      };
      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 [CA10A1__disappearanceTime__c]: ' + obj.CA10A1__disappearanceTime__c);
      if (obj.CA10A1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A1__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.CA10A1__status__c; } return this.out; };
      references1.push('Status [obj.CA10A1__status__c]: ' + obj.CA10A1__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'InService')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10A1__status__c') != 'InService'", currentStateMessage: "The SageMaker Endpoint is not in service.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      if (TextLib.isEmpty(obj.CA10A1__endpointConfigArn__c) || TextLib.isEmpty(obj.CA10A1__endpointConfig__c) || obj.CA10A1__endpointConfig__r.CA10A1__disappearanceTime__c != null) {
          return {status: 'UNDETERMINED', conditionIndex: 299, conditionText: "isEmptyLookup('CA10A1__endpointConfig__r')", currentStateMessage: "The Endpoint Configuration or its production variants are not present in the CMDB.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      function comparison5() {
          var comparisonLeft13 = jsonQueryChecked6();
          return comparisonLeft13 != null && 0.0 != null && comparisonLeft13 > 0.0;
      }
      function jsonQueryChecked6() {
          var input = extract8.call(extract8);
          var out;
          try {
              out = jmespath.search(input, 'length([?initialInstanceCount < `2`])');
          if (out != null && typeof out != 'number') {
              throw new Error("UNDETERMINED condition:307", {cause: {status: 'UNDETERMINED', conditionIndex: 307, conditionText: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount < `2`])').isResultTypeMismatch()", currentStateMessage: "Query did not return a number.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:308", {cause: {status: 'UNDETERMINED', conditionIndex: 308, conditionText: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount < `2`])').isEvaluationFailed()", currentStateMessage: "Failed to query the production variants JSON.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked9() {
          var input = extractChecked10();
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:305", {cause: {status: 'UNDETERMINED', conditionIndex: 305, conditionText: "extract('CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c').asJson().isEmpty()", currentStateMessage: "Endpoint Config Production Variants cannot be empty. Possible permission issue with sagemaker:DescribeEndpointConfig", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:306", {cause: {status: 'UNDETERMINED', conditionIndex: 306, conditionText: "extract('CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c').asJson().isInvalid()", currentStateMessage: "The Production Variants JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extractChecked10() {
          if (TextLib.isEmpty(obj.CA10A1__endpointConfigArn__c)) {
              throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "extractCheck(obj.CA10A1__endpointConfigArn__c)", currentStateMessage: "Related object via CA10A1__endpointConfigArn__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10A1__endpointConfig__c)) {
              throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "extractCheck(obj.CA10A1__endpointConfig__c)", currentStateMessage: "Related object via CA10A1__endpointConfig__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10A1__endpointConfig__r.CA10A1__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extractCheck(obj.CA10A1__endpointConfig__r.CA10A1__disappearanceTime__c)", currentStateMessage: "Related object via CA10A1__endpointConfig__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract11.call(extract11);
      }
      function fieldChecked12() {
          if (BytesLib.isEmpty(obj.CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c)) {
              throw new Error("UNDETERMINED condition:304", {cause: {status: 'UNDETERMINED', conditionIndex: 304, conditionText: "CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()", currentStateMessage: "Endpoint Config Production Variants cannot be empty. Possible permission issue with sagemaker:DescribeEndpointConfig", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c;
      }
      function extract11() { if (!this.out) { this.out = fieldChecked12(); } return this.out; };
      function extract8() { if (!this.out) { this.out = jsonChecked9(); } return this.out; };
      references1.push('Production Variants JSON [obj.CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c]: ' + obj.CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c);
      try {
          if (comparison5()) {
              return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount < `2`])') > number(0.0)", currentStateMessage: "At least one production variant in the endpoint configuration has an instance count less than 2.", currentStateReferences: references1.join('\n'), remediation: "Increase the instance count for all production variants to at least 2.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[4], conditionIndex:[400..499]
      function comparison14() {
          var comparisonLeft22 = jsonQueryChecked15();
          return comparisonLeft22 != null && 0.0 != null && comparisonLeft22 > 0.0;
      }
      function jsonQueryChecked15() {
          var input = extract17.call(extract17);
          var out;
          try {
              out = jmespath.search(input, 'length([?initialInstanceCount > `1`])');
          if (out != null && typeof out != 'number') {
              throw new Error("UNDETERMINED condition:407", {cause: {status: 'UNDETERMINED', conditionIndex: 407, conditionText: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount > `1`])').isResultTypeMismatch()", currentStateMessage: "Query did not return a number.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          } catch (e) {
              throw new Error("UNDETERMINED condition:408", {cause: {status: 'UNDETERMINED', conditionIndex: 408, conditionText: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount > `1`])').isEvaluationFailed()", currentStateMessage: "Failed to query the production variants JSON.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function jsonChecked18() {
          var input = extractChecked19();
          if (TextLib.isEmpty(input)) {
              throw new Error("UNDETERMINED condition:405", {cause: {status: 'UNDETERMINED', conditionIndex: 405, conditionText: "extract('CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c').asJson().isEmpty()", currentStateMessage: "Endpoint Config Production Variants cannot be empty. Possible permission issue with sagemaker:DescribeEndpointConfig", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          var out;
          try {
              out = JSON.parse(input);
          } catch (e) {
              throw new Error("UNDETERMINED condition:406", {cause: {status: 'UNDETERMINED', conditionIndex: 406, conditionText: "extract('CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c').asJson().isInvalid()", currentStateMessage: "The Production Variants JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}});
          }
          return out;
      }
      function extractChecked19() {
          if (TextLib.isEmpty(obj.CA10A1__endpointConfigArn__c)) {
              throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "extractCheck(obj.CA10A1__endpointConfigArn__c)", currentStateMessage: "Related object via CA10A1__endpointConfigArn__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10A1__endpointConfig__c)) {
              throw new Error("UNDETERMINED condition:402", {cause: {status: 'UNDETERMINED', conditionIndex: 402, conditionText: "extractCheck(obj.CA10A1__endpointConfig__c)", currentStateMessage: "Related object via CA10A1__endpointConfig__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (obj.CA10A1__endpointConfig__r.CA10A1__disappearanceTime__c != null) {
              throw new Error("UNDETERMINED condition:403", {cause: {status: 'UNDETERMINED', conditionIndex: 403, conditionText: "extractCheck(obj.CA10A1__endpointConfig__r.CA10A1__disappearanceTime__c)", currentStateMessage: "Related object via CA10A1__endpointConfig__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return extract20.call(extract20);
      }
      function fieldChecked21() {
          if (BytesLib.isEmpty(obj.CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c)) {
              throw new Error("UNDETERMINED condition:404", {cause: {status: 'UNDETERMINED', conditionIndex: 404, conditionText: "CA10A1__productionVariantsJson__c.delegatedTo(CA10A1__productionVariantsJson__c).isEmpty()", currentStateMessage: "Endpoint Config Production Variants cannot be empty. Possible permission issue with sagemaker:DescribeEndpointConfig", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A1__endpointConfig__r.CA10A1__productionVariantsJson__c;
      }
      function extract20() { if (!this.out) { this.out = fieldChecked21(); } return this.out; };
      function extract17() { if (!this.out) { this.out = jsonChecked18(); } return this.out; };
      try {
          if (comparison14()) {
              return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "extract('caJsonFrom__productionVariantsJson__c').jsonQueryText('length([?initialInstanceCount > `1`])') > number(0.0)", currentStateMessage: "All production variants for this endpoint have at least two instances configured.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'UNDETERMINED', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "Unable to determine the initial instance count of the Endpoint Config.", 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.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
          sObject.CA10A1__status__c AS CA10A1__status__c,
          sObject.CA10A1__endpointConfig__c AS CA10A1__endpointConfig__c,
          sObject.CA10A1__endpointConfigArn__c AS CA10A1__endpointConfigArn__c,
          sObject.Id AS Id,
          STRUCT (
              `CA10A1__endpointConfig__r`.Id AS Id,
              `CA10A1__endpointConfig__r`.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
              `CA10A1__endpointConfig__r`.CA10A1__productionVariantsJson__c AS CA10A1__productionVariantsJson__c
          ) AS CA10A1__endpointConfig__r,
          process_CA10A1__CaAwsSageMakerEndpoint__c(
              STRUCT(
                  sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                  sObject.CA10A1__status__c AS CA10A1__status__c,
                  sObject.CA10A1__endpointConfig__c AS CA10A1__endpointConfig__c,
                  sObject.CA10A1__endpointConfigArn__c AS CA10A1__endpointConfigArn__c,
                  sObject.Id AS Id,
                  STRUCT (
                      `CA10A1__endpointConfig__r`.Id AS Id,
                      `CA10A1__endpointConfig__r`.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                      `CA10A1__endpointConfig__r`.CA10A1__productionVariantsJson__c AS CA10A1__productionVariantsJson__c
                  ) AS CA10A1__endpointConfig__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A1__CaAwsSageMakerEndpoint__c()) AS sObject
      LEFT JOIN UNNEST(mock_CA10A1__CaAwsSageMakerEndpointConfig__c()) AS `CA10A1__endpointConfig__r`
          ON sObject.CA10A1__endpointConfig__c = `CA10A1__endpointConfig__r`.Id
  ) sObject ON sObject.Id = expectedResult.Id;
