code: def get_session_from_role(
      region: str, assume_role: str = None
  ) -> Session:
      """Method used to get the :class:`sagemaker.session.Session`  from a region and/or a role.
  
      Description:
          If invoked from a session with a role that lacks permissions, it can temporarily
          assume another role to perform certain tasks.
          If `assume_role` is not specified it will attempt to use the default sagemaker
          execution role to get the session to use the Feature Store runtime client.
  
      Args:
          assume_role (str): (Optional) role name to be assumed
          region (str): region name
  
      Returns:
          :class:`sagemaker.session.Session`
      """
      boto_session = boto3.Session(region_name=region)
  
      # It will try to assume the role specified
      if assume_role:
          sts = boto_session.client("sts", region_name=region)
  
          credentials = sts.assume_role(
              RoleArn=assume_role, RoleSessionName="SagemakerExecution"
          ).get("Credentials", {})
  
          access_key_id = credentials.get("AccessKeyId", None)
          secret_access_key = credentials.get("SecretAccessKey", None)
          session_token = credentials.get("SessionToken", None)
  
          boto_session = boto3.session.Session(
              region_name=region,
              aws_access_key_id=access_key_id,
              aws_secret_access_key=secret_access_key,
              aws_session_token=session_token,
          )
  
      sagemaker_session = Session(
          boto_session=boto_session,
          sagemaker_client=boto_session.client("sagemaker"),
          sagemaker_runtime_client=boto_session.client(
              "sagemaker-runtime"
          ),
          sagemaker_featurestore_runtime_client=boto_session.client(
              service_name="sagemaker-featurestore-runtime"
          ),
      )
  
      return sagemaker_session
  
file_path: sagemaker-python-sdk/src/sagemaker/feature_store/feature_utils.py
imports: from __future__ import absolute_import
  import re
  import logging
  from typing import Union
  from pathlib import Path
  import pandas
  import boto3
  from pandas import DataFrame, Series, read_csv
  from sagemaker.feature_store.feature_group import FeatureGroup
  from sagemaker.session import Session
label_desc: Use image node_id 1 for calling a global function with example usage: get_session_from_role(region, assume_role) and returns: sagemaker_session