code: def sagemaker_session_with_dynamically_generated_sagemaker_config(
      role_arn,
      kms_key_arn,
      sagemaker_client_config,
      sagemaker_runtime_config,
      boto_session,
      sagemaker_metrics_config,
  ):
      # This config needs to be dynamically generated so it can include the specific infra parameters
      # created/reused for the Integ tests
      config_as_dict = {
          "SchemaVersion": "1.0",
          "SageMaker": {
              "PythonSDK": {
                  "Modules": {
                      "Session": {
                          "DefaultS3ObjectKeyPrefix": S3_KEY_PREFIX,
                          # S3Bucket is omitted for now, because the tests support one S3 bucket at
                          # the moment and it would be hard to validate injection of this parameter
                          # if we use the same bucket that the rest of the tests are.
                      },
                  },
              },
              "EndpointConfig": {
                  "AsyncInferenceConfig": {
                      "OutputConfig": {"KmsKeyId": kms_key_arn}
                  },
                  "DataCaptureConfig": {"KmsKeyId": kms_key_arn},
                  "KmsKeyId": kms_key_arn,
                  "Tags": ENDPOINT_CONFIG_TAGS,
              },
              "Model": {
                  "EnableNetworkIsolation": True,
                  "ExecutionRoleArn": role_arn,
                  "Tags": MODEL_TAGS,
                  # VpcConfig is omitted for now, more info inside test
                  # test_sagemaker_config_cross_context_injection
              },
          },
      }
  
      dynamic_sagemaker_config_yaml_path = os.path.join(
          tempfile.gettempdir(), "dynamic_sagemaker_config.yaml"
      )
  
      # write to yaml file, and avoid references and anchors
      yaml.Dumper.ignore_aliases = lambda *args: True
      with open(
          pathlib.Path(dynamic_sagemaker_config_yaml_path), "w"
      ) as f:
          yaml.dump(
              config_as_dict,
              f,
              sort_keys=False,
              default_flow_style=False,
          )
  
      # other Session inputs (same as sagemaker_session fixture)
      sagemaker_client_config.setdefault(
          "config", Config(retries=dict(max_attempts=10))
      )
      sagemaker_client = (
          boto_session.client("sagemaker", **sagemaker_client_config)
          if sagemaker_client_config
          else None
      )
      runtime_client = (
          boto_session.client(
              "sagemaker-runtime", **sagemaker_runtime_config
          )
          if sagemaker_runtime_config
          else None
      )
      metrics_client = (
          boto_session.client(
              "sagemaker-metrics", **sagemaker_metrics_config
          )
          if sagemaker_metrics_config
          else None
      )
  
      session = Session(
          boto_session=boto_session,
          sagemaker_client=sagemaker_client,
          sagemaker_runtime_client=runtime_client,
          sagemaker_metrics_client=metrics_client,
          sagemaker_config=load_sagemaker_config(
              [dynamic_sagemaker_config_yaml_path]
          ),
      )
  
      return session
  
imports: from __future__ import absolute_import
  import os
  import pathlib
  import tempfile
  import pytest
  import yaml
  from botocore.config import Config
  from sagemaker import PipelineModel, image_uris, Model, Predictor, Session
  from sagemaker.config import load_sagemaker_config
  from sagemaker.model_monitor import DataCaptureConfig
  from sagemaker.s3 import S3Uploader
  from sagemaker.sparkml import SparkMLModel
  from sagemaker.utils import sagemaker_timestamp
  from tests.integ import DATA_DIR
  from tests.integ.kms_utils import get_or_create_kms_key
  from tests.integ.test_inference_pipeline import SCHEMA
  from tests.integ.timeout import timeout_and_delete_endpoint_by_name
label_desc: Use image node_id 5 for calling a global function with example usage: sagemaker_session_with_dynamically_generated_sagemaker_config(role_arn, kms_key_arn, sagemaker_client_config, sagemaker_runtime_config, boto_session, sagemaker_metrics_config) and returns: session