---
policy: /ce/ca/aws/sagemaker/notebook-instance-in-vpc
logic: /ce/ca/aws/sagemaker/notebook-instance-in-vpc/prod.logic.yaml
executionTime: 2026-01-24T12:02:26.757652612Z
generationMs: 72
executionMs: 690
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: 299
      actual: 299
    conditionText:
      expected: isEmptyLookup('CA10A1__subnet__r')
      actual: isEmptyLookup('CA10A1__subnet__r')
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: notEmptyLookup('CA10A1__subnet__r')
      actual: notEmptyLookup('CA10A1__subnet__r')
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10A1__disappearanceTime__c)
      actual: isDisappeared(CA10A1__disappearanceTime__c)
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/sagemaker/notebook-instance-in-vpc/policy.yaml
    md5Hash: 96EA542826B9BDC78B531FCD11A5A693
    content: "---\nnames:\n  full: \"AWS SageMaker Notebook Instance is not in a VPC\"\
      \n  contextual: \"Notebook Instance is not in a VPC\"\ndescription: >\n  Ensure\
      \ that AWS SageMaker notebook instances are launched within a Virtual Private\
      \ Cloud (VPC). \n  This allows you to secure the communication between the notebook\
      \ and other resources, \n  such as S3 buckets or databases, by using private\
      \ network paths and VPC endpoints.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\
      \  - \"SECURITY\"\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/secure-access\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/sagemaker/02\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[SageMaker.2] SageMaker notebook instances should be launched\
      \ in a custom VPC\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/sagemaker-controls.html#sagemaker-2\""
  - path: /ce/ca/aws/sagemaker/notebook-instance-in-vpc/prod.logic.yaml
    md5Hash: 4D3E398E3FC7CC20B1B30726AE19D95E
    content: |-
      ---
      inputType: "CA10A1__CaAwsSageMakerNotebookInstance__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10A1__CaAwsSageMakerNotebookInstance__c/object.extracts.yaml"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The SageMaker Notebook Instance is not currently in service."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10A1__status__c"
              right:
                TEXT: "InService"
        - status: "INCOMPLIANT"
          currentStateMessage: "The notebook instance is not associated with a VPC."
          remediationMessage: "Configure the notebook instance to reside within a VPC subnet."
          check:
            IS_EMPTY_LOOKUP: "CA10A1__subnet__r"
        - status: "COMPLIANT"
          currentStateMessage: "The notebook instance is launched within a VPC."
          check:
            NOT_EMPTY_LOOKUP: "CA10A1__subnet__r"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the fields."
  - path: /ce/ca/aws/sagemaker/notebook-instance-in-vpc/test-data.json
    md5Hash: 2B1FB79E0FB62C8688FF65B66F9F88EA
    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": "Stopped",
              "CA10A1__subnet__c": "test1_1",
              "CA10A1__subnetId__c": "subnet-id",
              "Id": "test1",
              "CA10A1__subnet__r": {
                  "Id": "test1_1",
                  "CA10__disappearanceTime__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "isEmptyLookup('CA10A1__subnet__r')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "InService",
              "CA10A1__subnet__c": "",
              "CA10A1__subnetId__c": "",
              "Id": "test2",
              "CA10A1__subnet__r": {
                  "Id": null,
                  "CA10__disappearanceTime__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "399",
                  "conditionText": "notEmptyLookup('CA10A1__subnet__r')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__status__c": "InService",
              "CA10A1__subnet__c": "test3_1",
              "CA10A1__subnetId__c": "subnet-id",
              "Id": "test3",
              "CA10A1__subnet__r": {
                  "Id": "test3_1",
                  "CA10__disappearanceTime__c": null
              }
          },
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10A1__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2026-01-16T01:27:51Z"
              },
              "CA10A1__disappearanceTime__c": "2026-01-16T01:27:51Z",
              "CA10A1__status__c": "InService",
              "CA10A1__subnet__c": "test4_1",
              "CA10A1__subnetId__c": "subnet-id",
              "Id": "test4",
              "CA10A1__subnet__r": {
                  "Id": "test4_1",
                  "CA10__disappearanceTime__c": null
              }
          }
      ]
  - path: /types/CA10A1__CaAwsSageMakerNotebookInstance__c/object.extracts.yaml
    md5Hash: 6890CE14909F3170C7201BDF33753985
    content: "---\nextracts:\n# Nullable.\n  - name: CA10A1__kmsKeyId__c\n    value:\n\
      \      FIELD: \n        path: CA10A1__kmsKeyId__c\n# Values: Pending | InService\
      \ | Stopping | Stopped | Failed | Deleting | Updating. Not nullable\n  - name:\
      \ CA10A1__status__c\n    value:\n      FIELD: \n        path: CA10A1__status__c\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10A1__status__c\"\n            currentStateMessage: \"Notebook Instance Status\
      \ cannot be empty. Possible permissions issue with sagemaker:DescribeNotebookInstance\"\
      \n# Values: Enabled | Disabled. Not nullable\n  - name: CA10A1__directInternetAccess__c\n\
      \    value:\n      FIELD: \n        path: CA10A1__directInternetAccess__c\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: \"\
      CA10A1__directInternetAccess__c\"\n            currentStateMessage: \"Notebook\
      \ Instance Direct Internet Access cannot be empty. Possible permissions issue\
      \ with sagemaker:DescribeNotebookInstance\"\n# Values: Enabled | Disabled. Not\
      \ nullable\n  - name: CA10A1__rootAccess__c\n    value:\n      FIELD: \n   \
      \     path: CA10A1__rootAccess__c\n        undeterminedIf:\n          noAccessDelegate:\n\
      \            path: \"CA10A1__rootAccess__c\"\n            currentStateMessage:\
      \ \"Notebook Instance Direct Internet Access cannot be empty. Possible permissions\
      \ issue with sagemaker:DescribeNotebookInstance\"\n"
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" : "299",
      "conditionText" : "isEmptyLookup('CA10A1__subnet__r')",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "399",
      "conditionText" : "notEmptyLookup('CA10A1__subnet__r')",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10A1__disappearanceTime__c)",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsSageMakerNotebookInstance__c()
  RETURNS ARRAY<STRUCT<
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__status__c STRING,
      CA10A1__subnet__c STRING,
      CA10A1__subnetId__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" : "Stopped",
    "CA10A1__subnet__c" : "test1_1",
    "CA10A1__subnetId__c" : "subnet-id",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "InService",
    "CA10A1__subnet__c" : "",
    "CA10A1__subnetId__c" : "",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__status__c" : "InService",
    "CA10A1__subnet__c" : "test3_1",
    "CA10A1__subnetId__c" : "subnet-id",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "CA10A1__disappearanceTime__c" : new Date("2026-01-16T01:27:51Z"),
    "CA10A1__status__c" : "InService",
    "CA10A1__subnet__c" : "test4_1",
    "CA10A1__subnetId__c" : "subnet-id",
    "Id" : "test4"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsSubnet__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : "test1_1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : null
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : "test3_1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-16T01:27:51Z")
    },
    "Id" : "test4_1"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A1__CaAwsSageMakerNotebookInstance__c(
      obj STRUCT<
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__status__c STRING,
          CA10A1__subnet__c STRING,
          CA10A1__subnetId__c STRING,
          Id STRING,
          CA10A1__subnet__r STRUCT<
              Id STRING,
              CA10__disappearanceTime__c TIMESTAMP
          >
      >,
      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 [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 fieldChecked4() {
          if (TextLib.isEmpty(obj.CA10A1__status__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10A1__status__c.delegatedTo(CA10A1__status__c).isEmpty()", currentStateMessage: "Notebook Instance Status cannot be empty. Possible permissions issue with sagemaker:DescribeNotebookInstance", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A1__status__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Status [obj.CA10A1__status__c]: ' + obj.CA10A1__status__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'InService')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10A1__status__c') != 'InService'", currentStateMessage: "The SageMaker Notebook Instance is not currently in service.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      if (TextLib.isEmpty(obj.CA10A1__subnetId__c) || TextLib.isEmpty(obj.CA10A1__subnet__c) || obj.CA10A1__subnet__r.CA10__disappearanceTime__c != null) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "isEmptyLookup('CA10A1__subnet__r')", currentStateMessage: "The notebook instance is not associated with a VPC.", currentStateReferences: references1.join('\n'), remediation: "Configure the notebook instance to reside within a VPC subnet.", runtimeError: null};
      }
      // condition[3], conditionIndex:[300..399]
      if (TextLib.isNotEmpty(obj.CA10A1__subnetId__c) && TextLib.isNotEmpty(obj.CA10A1__subnet__c) && obj.CA10A1__subnet__r.CA10__disappearanceTime__c == null) {
          return {status: 'COMPLIANT', conditionIndex: 399, conditionText: "notEmptyLookup('CA10A1__subnet__r')", currentStateMessage: "The notebook instance is launched within a VPC.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", 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__subnet__c AS CA10A1__subnet__c,
          sObject.CA10A1__subnetId__c AS CA10A1__subnetId__c,
          sObject.Id AS Id,
          STRUCT (
              `CA10A1__subnet__r`.Id AS Id,
              `CA10A1__subnet__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
          ) AS CA10A1__subnet__r,
          process_CA10A1__CaAwsSageMakerNotebookInstance__c(
              STRUCT(
                  sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                  sObject.CA10A1__status__c AS CA10A1__status__c,
                  sObject.CA10A1__subnet__c AS CA10A1__subnet__c,
                  sObject.CA10A1__subnetId__c AS CA10A1__subnetId__c,
                  sObject.Id AS Id,
                  STRUCT (
                      `CA10A1__subnet__r`.Id AS Id,
                      `CA10A1__subnet__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c
                  ) AS CA10A1__subnet__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A1__CaAwsSageMakerNotebookInstance__c()) AS sObject
      LEFT JOIN UNNEST(mock_CA10__CaAwsSubnet__c()) AS `CA10A1__subnet__r`
          ON sObject.CA10A1__subnet__c = `CA10A1__subnet__r`.Id
  ) sObject ON sObject.Id = expectedResult.Id;
