code: def assume_role(role_name, credentials, role_arn, role_session_name, silent = False):
      
      external_id = credentials.pop('ExternalId') if 'ExternalId' in credentials else None
      # Connect to STS
      sts_client = connect_service('sts', credentials, silent = silent)
      # Set required arguments for assume role call
      sts_args = {
        'RoleArn': role_arn,
        'RoleSessionName': role_session_name
      }
      # MFA used ?
      if 'mfa_serial' in credentials and 'mfa_code' in credentials:
        sts_args['TokenCode'] = credentials['mfa_code']
        sts_args['SerialNumber'] = credentials['mfa_serial']
      # External ID used ?
      if external_id:
        sts_args['ExternalId'] = external_id
      # Assume the role
      sts_response = sts_client.assume_role(**sts_args)
      credentials = sts_response['Credentials']
      cached_credentials_filename = get_cached_credentials_filename(role_name, role_arn)
      #with open(cached_credentials_filename, 'wt+') as f:
      #   write_data_to_file(f, sts_response, True, False)
      cached_credentials_path = os.path.dirname(cached_credentials_filename)
      if not os.path.isdir(cached_credentials_path):
          os.makedirs(cached_credentials_path)
      save_blob_as_json(cached_credentials_filename, sts_response, True, False) # blob, force_write, debug):
      return credentials
docs: Assume role and save credentials
  
      :param role_name:
      :param credentials:
      :param role_arn:
      :param role_session_name:
      :param silent:
      :return: