code: def _add_role_to_policy(
      kms_client,
      account_id,
      role_arn,
      region,
      alias=KEY_ALIAS,
      sagemaker_role="SageMakerRole",
  ):
      key_id = _get_kms_key_id(kms_client, alias)
      policy = kms_client.get_key_policy(
          KeyId=key_id, PolicyName=POLICY_NAME
      )
      policy = json.loads(policy["Policy"])
      principal = policy["Statement"][0]["Principal"]["AWS"]
  
      if role_arn not in principal or sagemaker_role not in principal:
          principal = PRINCIPAL_TEMPLATE.format(
              partition=utils._aws_partition(region),
              account_id=account_id,
              role_arn=role_arn,
              sagemaker_role=sagemaker_role,
          )
  
          kms_client.put_key_policy(
              KeyId=key_id,
              PolicyName=POLICY_NAME,
              Policy=KEY_POLICY.format(
                  id=POLICY_NAME, principal=principal
              ),
          )
  
file_path: sagemaker-python-sdk/tests/integ/kms_utils.py
imports: from __future__ import absolute_import
  import contextlib
  import json
  from sagemaker import utils
label_desc: Use image node_id 4 for calling a global function with example usage: _add_role_to_policy(kms_client, account_id, role_arn, region, alias, sagemaker_role) without return types