---
policy: /ce/ca/aws/lambda/function-multi-az
logic: /ce/ca/aws/lambda/function-multi-az/prod.logic.yaml
executionTime: 2026-01-17T12:02:54.41543344Z
generationMs: 76
executionMs: 1287
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10__disappearanceTime__c)
      actual: isDisappeared(CA10__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: CA10__AWS_Lambda_Function_Versions__r.has(COMPLIANT)
      actual: CA10__AWS_Lambda_Function_Versions__r.has(COMPLIANT)
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: CA10__vpcId__c.isEmpty()
      actual: CA10__vpcId__c.isEmpty()
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 399
      actual: 399
    conditionText:
      expected: CA10__AWS_Lambda_Function_Subnet_Links__r.count(COMPLIANT) < number(2.0)
      actual: CA10__AWS_Lambda_Function_Subnet_Links__r.count(COMPLIANT) < number(2.0)
    runtimeError: {}
  - id: test5
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 400
      actual: 400
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/lambda/function-multi-az/policy.yaml
    md5Hash: 4C8F353219B32A635DFD6D19A6A04FCA
    content: "---\nnames:\n  full: \"AWS Lambda Function is not in multiple Availability\
      \ Zones\"\n  contextual: \"Function is not in multiple Availability Zones\"\n\
      description: >\n  Ensure that AWS Lambda functions configured with a VPC are\
      \ associated with subnets \n  in at least two Availability Zones. Spanning multiple\
      \ AZs provides high availability \n  in the event of a service disruption in\
      \ a single zone.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"RELIABILITY\"\
      \nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-reliability/system-configuration\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/lambda/05\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[Lambda.5] VPC Lambda functions should operate in multiple Availability\
      \ Zones\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/lambda-controls.html#lambda-5\""
  - path: /ce/ca/aws/lambda/function-multi-az/prod.logic.yaml
    md5Hash: 9F6105ACEDF004882CA998D4241BA05C
    content: "---\ninputType: \"CA10__CaAwsLambdaFunction__c\"\nimportExtracts:\n\
      \  - file: \"/types/CA10__CaAwsLambdaFunction__c/object.extracts.yaml\"\ntestData:\n\
      \  - file: \"test-data.json\"\nconditions:\n  - status: \"INAPPLICABLE\"\n \
      \   currentStateMessage: \"Lambda@Edge functions do not support VPC association.\"\
      \n    check:\n      RELATED_LIST_HAS:\n        status: \"COMPLIANT\"\n     \
      \   relationshipName: \"CA10__AWS_Lambda_Function_Versions__r\"\n  - status:\
      \ \"INAPPLICABLE\"\n    currentStateMessage: \"The Lambda function is not associated\
      \ with a VPC.\"\n    check:\n      IS_EMPTY:\n        arg:\n          FIELD:\n\
      \            path: \"CA10__vpcId__c\"\n  - status: \"INCOMPLIANT\"\n    currentStateMessage:\
      \ \"The Lambda function is associated with only one Availability Zone.\"\n \
      \   remediationMessage: \"Update the Lambda function configuration to include\
      \ subnets in at least two different AZs.\"\n    check:\n      LESS_THAN:\n \
      \       left:\n          RELATED_LIST_COUNT:\n            status: \"COMPLIANT\"\
      \n            relationshipName: \"CA10__AWS_Lambda_Function_Subnet_Links__r\"\
      \n        right:\n          NUMBER: 2.0\notherwise:\n  status: \"COMPLIANT\"\
      \n  currentStateMessage: \"The Lambda function is associated with a VPC.\"\n\
      relatedLists:\n  - relationshipName: \"CA10__AWS_Lambda_Function_Versions__r\"\
      \n    conditions:\n      - status: \"COMPLIANT\"\n        currentStateMessage:\
      \ \"This is Lambda@Edge function.\"\n        check:\n          RELATED_LIST_HAS:\n\
      \            status: \"COMPLIANT\"\n            relationshipName: \"CA10__AWS_CloudFront_Lambda_Func_Associations__r\"\
      \n    otherwise:\n      status: \"INAPPLICABLE\"\n      currentStateMessage:\
      \ \"This function version does not have an association with CloudFront.\"\n\
      \    relatedLists:\n      - relationshipName: \"CA10__AWS_CloudFront_Lambda_Func_Associations__r\"\
      \n        conditions: []\n        otherwise:\n          status: \"COMPLIANT\"\
      \n          currentStateMessage: \"This is Lambda@Edge function.\" \n  - relationshipName:\
      \ \"CA10__AWS_Lambda_Function_Subnet_Links__r\"\n    conditions: []\n    otherwise:\n\
      \      status: \"COMPLIANT\"\n      currentStateMessage: \"This is a subnet\
      \ attached to the function.\""
  - path: /ce/ca/aws/lambda/function-multi-az/test-data.json
    md5Hash: 7A2F4B5F37D7F424309C12BC54FBA1D9
    content: |-
      [
          {
              "CA10__AWS_Lambda_Function_Versions__r": [],
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "conditionIndex": 99,
                  "status": "DISAPPEARED"
              },
              "context": {
                  "snapshotTime": "2026-01-12T23:29:54Z"
              },
              "Id": "test1",
              "CA10__AWS_Lambda_Function_Subnet_Links__r": [],
              "CA10__disappearanceTime__c": "2025-07-29T12:38:18Z",
              "CA10__vpcId__c": ""
          },
          {
              "CA10__AWS_Lambda_Function_Versions__r": [
                  {
                      "CA10__function__c": "test2",
                      "CA10__AWS_CloudFront_Lambda_Func_Associations__r": [
                          {
                              "Id": "test2_2",
                              "CA10__disappearanceTime__c": null,
                              "CA10__lambdaFunctionVersion__c": "test2_1"
                          }
                      ],
                      "Id": "test2_1",
                      "CA10__disappearanceTime__c": null
                  }
              ],
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "CA10__AWS_Lambda_Function_Versions__r.has(COMPLIANT)",
                  "conditionIndex": 199,
                  "status": "INAPPLICABLE"
              },
              "context": {
                  "snapshotTime": "2026-01-12T23:29:54Z"
              },
              "Id": "test2",
              "CA10__AWS_Lambda_Function_Subnet_Links__r": [],
              "CA10__disappearanceTime__c": null,
              "CA10__vpcId__c": ""
          },
          {
              "CA10__AWS_Lambda_Function_Versions__r": [
                  {
                      "CA10__function__c": "test3",
                      "CA10__AWS_CloudFront_Lambda_Func_Associations__r": [],
                      "Id": "test3_1",
                      "CA10__disappearanceTime__c": null
                  }
              ],
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "CA10__vpcId__c.isEmpty()",
                  "conditionIndex": 299,
                  "status": "INAPPLICABLE"
              },
              "context": {
                  "snapshotTime": "2026-01-12T23:29:54Z"
              },
              "Id": "test3",
              "CA10__AWS_Lambda_Function_Subnet_Links__r": [],
              "CA10__disappearanceTime__c": null,
              "CA10__vpcId__c": ""
          },
          {
              "CA10__AWS_Lambda_Function_Versions__r": [
                  {
                      "CA10__function__c": "test4",
                      "CA10__AWS_CloudFront_Lambda_Func_Associations__r": [],
                      "Id": "test4_1",
                      "CA10__disappearanceTime__c": null
                  }
              ],
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "CA10__AWS_Lambda_Function_Subnet_Links__r.count(COMPLIANT) < number(2.0)",
                  "conditionIndex": 399,
                  "status": "INCOMPLIANT"
              },
              "context": {
                  "snapshotTime": "2026-01-12T23:29:54Z"
              },
              "Id": "test4",
              "CA10__AWS_Lambda_Function_Subnet_Links__r": [
                  {
                      "CA10__function__c": "test4",
                      "Id": "test4_2",
                      "CA10__disappearanceTime__c": null
                  }
              ],
              "CA10__disappearanceTime__c": null,
              "CA10__vpcId__c": "vpc-id"
          },
          {
              "CA10__AWS_Lambda_Function_Versions__r": [
                  {
                      "CA10__function__c": "test5",
                      "CA10__AWS_CloudFront_Lambda_Func_Associations__r": [],
                      "Id": "test5_1",
                      "CA10__disappearanceTime__c": null
                  }
              ],
              "expectedResult": {
                  "runtimeError": null,
                  "conditionText": "otherwise",
                  "conditionIndex": 400,
                  "status": "COMPLIANT"
              },
              "context": {
                  "snapshotTime": "2026-01-12T23:29:54Z"
              },
              "Id": "test5",
              "CA10__AWS_Lambda_Function_Subnet_Links__r": [
                  {
                      "CA10__function__c": "test5",
                      "Id": "test5_2",
                      "CA10__disappearanceTime__c": null
                  },
                  {
                      "CA10__function__c": "test5",
                      "Id": "test5_3",
                      "CA10__disappearanceTime__c": null
                  }
              ],
              "CA10__disappearanceTime__c": null,
              "CA10__vpcId__c": "vpc-id"
          }
      ]
  - path: /types/CA10__CaAwsLambdaFunction__c/object.extracts.yaml
    md5Hash: AC42D0E20DDB5A13477C5EE7A9A969D6
    content: "---\nextracts:\n# Nullable. Can't have no access, retrieved via lambda:ListFunctions\n\
      \  - name: \"CA10__vpcId__c\"\n    value: \n      FIELD:\n        path: \"CA10__vpcId__c\"\
      \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" : {
      "runtimeError" : null,
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "conditionIndex" : 99,
      "status" : "DISAPPEARED"
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "CA10__AWS_Lambda_Function_Versions__r.has(COMPLIANT)",
      "conditionIndex" : 199,
      "status" : "INAPPLICABLE"
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "CA10__vpcId__c.isEmpty()",
      "conditionIndex" : 299,
      "status" : "INAPPLICABLE"
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "CA10__AWS_Lambda_Function_Subnet_Links__r.count(COMPLIANT) < number(2.0)",
      "conditionIndex" : 399,
      "status" : "INCOMPLIANT"
    }
  }, {
    "Id" : "test5",
    "expectedResult" : {
      "runtimeError" : null,
      "conditionText" : "otherwise",
      "conditionIndex" : 400,
      "status" : "COMPLIANT"
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsLambdaFunction__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__vpcId__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-07-29T12:38:18Z"),
    "CA10__vpcId__c" : "",
    "Id" : "test1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__vpcId__c" : "",
    "Id" : "test2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__vpcId__c" : "",
    "Id" : "test3"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__vpcId__c" : "vpc-id",
    "Id" : "test4"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__vpcId__c" : "vpc-id",
    "Id" : "test5"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsLambdaFunctionVersion__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__function__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__function__c" : "test2",
    "Id" : "test2_1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__function__c" : "test3",
    "Id" : "test3_1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__function__c" : "test4",
    "Id" : "test4_1"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__function__c" : "test5",
    "Id" : "test5_1"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsCloudFrontLambdaFunctionAssociation__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__lambdaFunctionVersion__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__lambdaFunctionVersion__c" : "test2_1",
    "Id" : "test2_2"
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsLambdaFunctionSubnetLink__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__function__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__function__c" : "test4",
    "Id" : "test4_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__function__c" : "test5",
    "Id" : "test5_2"
  }, {
    "context" : {
      "snapshotTime" : new Date("2026-01-12T23:29:54Z")
    },
    "CA10__function__c" : "test5",
    "Id" : "test5_3"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsLambdaFunction__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__vpcId__c STRING,
          Id STRING,
          CA10__AWS_Lambda_Function_Versions__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__function__c STRING,
              Id STRING,
              CA10__AWS_CloudFront_Lambda_Func_Associations__r ARRAY<STRUCT<
                  CA10__disappearanceTime__c TIMESTAMP,
                  CA10__lambdaFunctionVersion__c STRING,
                  Id STRING,
                  result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
              >>,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
          >>,
          CA10__AWS_Lambda_Function_Subnet_Links__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__function__c STRING,
              Id STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError 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};
      }
      var count_CA10__AWS_Lambda_Function_Versions__r_COMPLIANT2 = 0;
      if (obj.CA10__AWS_Lambda_Function_Versions__r != null) {
          for (var i3 = 0; i3 < obj.CA10__AWS_Lambda_Function_Versions__r.length; i3++) {
              if (typeof(obj.CA10__AWS_Lambda_Function_Versions__r[i3].status) !== 'undefined') {
                  if (obj.CA10__AWS_Lambda_Function_Versions__r[i3].status == 'COMPLIANT') {
                      count_CA10__AWS_Lambda_Function_Versions__r_COMPLIANT2 += obj.CA10__AWS_Lambda_Function_Versions__r[i3].count;
                  }
              } else  {
                  if (obj.CA10__AWS_Lambda_Function_Versions__r[i3].result.status == 'COMPLIANT') {
                      count_CA10__AWS_Lambda_Function_Versions__r_COMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__AWS_Lambda_Function_Versions__r] ' + (count_CA10__AWS_Lambda_Function_Versions__r_COMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status');
      if (count_CA10__AWS_Lambda_Function_Versions__r_COMPLIANT2 > 0) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "CA10__AWS_Lambda_Function_Versions__r.has(COMPLIANT)", currentStateMessage: "Lambda@Edge functions do not support VPC association.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      references1.push('VPC ID [obj.CA10__vpcId__c]: ' + obj.CA10__vpcId__c);
      if (TextLib.isEmpty(obj.CA10__vpcId__c)) {
          return {status: 'INAPPLICABLE', conditionIndex: 299, conditionText: "CA10__vpcId__c.isEmpty()", currentStateMessage: "The Lambda function is not associated with a VPC.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      var count_CA10__AWS_Lambda_Function_Subnet_Links__r_COMPLIANT6 = 0;
      if (obj.CA10__AWS_Lambda_Function_Subnet_Links__r != null) {
          for (var i7 = 0; i7 < obj.CA10__AWS_Lambda_Function_Subnet_Links__r.length; i7++) {
              if (typeof(obj.CA10__AWS_Lambda_Function_Subnet_Links__r[i7].status) !== 'undefined') {
                  if (obj.CA10__AWS_Lambda_Function_Subnet_Links__r[i7].status == 'COMPLIANT') {
                      count_CA10__AWS_Lambda_Function_Subnet_Links__r_COMPLIANT6 += obj.CA10__AWS_Lambda_Function_Subnet_Links__r[i7].count;
                  }
              } else  {
                  if (obj.CA10__AWS_Lambda_Function_Subnet_Links__r[i7].result.status == 'COMPLIANT') {
                      count_CA10__AWS_Lambda_Function_Subnet_Links__r_COMPLIANT6 += 1;
                  }
              }
          }
      }
      // condition[3], conditionIndex:[300..399]
      references1.push('Related list [CA10__AWS_Lambda_Function_Subnet_Links__r] has ' + count_CA10__AWS_Lambda_Function_Subnet_Links__r_COMPLIANT6 + ' objects in COMPLIANT status');
      if (count_CA10__AWS_Lambda_Function_Subnet_Links__r_COMPLIANT6 != null && 2.0 != null && count_CA10__AWS_Lambda_Function_Subnet_Links__r_COMPLIANT6 < 2.0) {
          return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "CA10__AWS_Lambda_Function_Subnet_Links__r.count(COMPLIANT) < number(2.0)", currentStateMessage: "The Lambda function is associated with only one Availability Zone.", currentStateReferences: references1.join('\n'), remediation: "Update the Lambda function configuration to include subnets in at least two different AZs.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "The Lambda function is associated with a VPC.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_Lambda_Function_Versions__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__function__c STRING,
          Id STRING,
          CA10__AWS_CloudFront_Lambda_Func_Associations__r ARRAY<STRUCT<
              CA10__disappearanceTime__c TIMESTAMP,
              CA10__lambdaFunctionVersion__c STRING,
              Id STRING,
              result STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError 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 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};
      }
      var count_CA10__AWS_CloudFront_Lambda_Func_Associations__r_COMPLIANT2 = 0;
      if (obj.CA10__AWS_CloudFront_Lambda_Func_Associations__r != null) {
          for (var i3 = 0; i3 < obj.CA10__AWS_CloudFront_Lambda_Func_Associations__r.length; i3++) {
              if (typeof(obj.CA10__AWS_CloudFront_Lambda_Func_Associations__r[i3].status) !== 'undefined') {
                  if (obj.CA10__AWS_CloudFront_Lambda_Func_Associations__r[i3].status == 'COMPLIANT') {
                      count_CA10__AWS_CloudFront_Lambda_Func_Associations__r_COMPLIANT2 += obj.CA10__AWS_CloudFront_Lambda_Func_Associations__r[i3].count;
                  }
              } else  {
                  if (obj.CA10__AWS_CloudFront_Lambda_Func_Associations__r[i3].result.status == 'COMPLIANT') {
                      count_CA10__AWS_CloudFront_Lambda_Func_Associations__r_COMPLIANT2 += 1;
                  }
              }
          }
      }
      // condition[1], conditionIndex:[100..199]
      references1.push('Related list [CA10__AWS_CloudFront_Lambda_Func_Associations__r] ' + (count_CA10__AWS_CloudFront_Lambda_Func_Associations__r_COMPLIANT2 > 0 ? 'has' : 'does not have') + ' objects in COMPLIANT status');
      if (count_CA10__AWS_CloudFront_Lambda_Func_Associations__r_COMPLIANT2 > 0) {
          return {status: 'COMPLIANT', conditionIndex: 199, conditionText: "CA10__AWS_CloudFront_Lambda_Func_Associations__r.has(COMPLIANT)", currentStateMessage: "This is Lambda@Edge function.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'INAPPLICABLE', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This function version does not have an association with CloudFront.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_Lambda_Function_Versions__r_CA10__AWS_CloudFront_Lambda_Func_Associations__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__lambdaFunctionVersion__c STRING,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "This is Lambda@Edge function.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;

  CREATE TEMP FUNCTION process_CA10__AWS_Lambda_Function_Subnet_Links__r(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__function__c STRING,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c);
      if (obj.CA10__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 100, conditionText: "otherwise", currentStateMessage: "This is a subnet attached to the function.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__vpcId__c AS CA10__vpcId__c,
          sObject.Id AS Id,
          `CA10__AWS_Lambda_Function_Versions__r`.arr AS CA10__AWS_Lambda_Function_Versions__r,
          `CA10__AWS_Lambda_Function_Subnet_Links__r`.arr AS CA10__AWS_Lambda_Function_Subnet_Links__r,
          process_CA10__CaAwsLambdaFunction__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__vpcId__c AS CA10__vpcId__c,
                  sObject.Id AS Id,
                  `CA10__AWS_Lambda_Function_Versions__r`.arr AS CA10__AWS_Lambda_Function_Versions__r,
                  `CA10__AWS_Lambda_Function_Subnet_Links__r`.arr AS CA10__AWS_Lambda_Function_Subnet_Links__r
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsLambdaFunction__c()) AS sObject
      LEFT JOIN (
          SELECT
              sObject.CA10__function__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__function__c AS CA10__function__c,
                      sObject.Id AS Id,
                      `CA10__AWS_CloudFront_Lambda_Func_Associations__r`.arr AS CA10__AWS_CloudFront_Lambda_Func_Associations__r,
                      process_CA10__AWS_Lambda_Function_Versions__r(
                          STRUCT(
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__function__c AS CA10__function__c,
                              sObject.Id AS Id,
                              `CA10__AWS_CloudFront_Lambda_Func_Associations__r`.arr AS CA10__AWS_CloudFront_Lambda_Func_Associations__r
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsLambdaFunctionVersion__c()) AS sObject
          LEFT JOIN (
              SELECT
                  sObject.CA10__lambdaFunctionVersion__c,
                  ARRAY_AGG(
                      STRUCT(
                          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                          sObject.CA10__lambdaFunctionVersion__c AS CA10__lambdaFunctionVersion__c,
                          sObject.Id AS Id,
                          process_CA10__AWS_Lambda_Function_Versions__r_CA10__AWS_CloudFront_Lambda_Func_Associations__r(
                              STRUCT(
                                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                                  sObject.CA10__lambdaFunctionVersion__c AS CA10__lambdaFunctionVersion__c,
                                  sObject.Id AS Id
                              ),
                              sObject.context.snapshotTime
                          ) as result
                      )
                  ) AS arr
              FROM UNNEST(mock_CA10__CaAwsCloudFrontLambdaFunctionAssociation__c()) AS sObject
              GROUP BY sObject.CA10__lambdaFunctionVersion__c
          ) AS `CA10__AWS_CloudFront_Lambda_Func_Associations__r`
              ON sObject.Id = `CA10__AWS_CloudFront_Lambda_Func_Associations__r`.CA10__lambdaFunctionVersion__c
          GROUP BY sObject.CA10__function__c
      ) AS `CA10__AWS_Lambda_Function_Versions__r`
          ON sObject.Id = `CA10__AWS_Lambda_Function_Versions__r`.CA10__function__c
      LEFT JOIN (
          SELECT
              sObject.CA10__function__c,
              ARRAY_AGG(
                  STRUCT(
                      sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                      sObject.CA10__function__c AS CA10__function__c,
                      sObject.Id AS Id,
                      process_CA10__AWS_Lambda_Function_Subnet_Links__r(
                          STRUCT(
                              sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                              sObject.CA10__function__c AS CA10__function__c,
                              sObject.Id AS Id
                          ),
                          sObject.context.snapshotTime
                      ) as result
                  )
              ) AS arr
          FROM UNNEST(mock_CA10__CaAwsLambdaFunctionSubnetLink__c()) AS sObject
          GROUP BY sObject.CA10__function__c
      ) AS `CA10__AWS_Lambda_Function_Subnet_Links__r`
          ON sObject.Id = `CA10__AWS_Lambda_Function_Subnet_Links__r`.CA10__function__c
  ) sObject ON sObject.Id = expectedResult.Id;
