UpdateAlias搭配使用 Amazon SDK或 CLI - Amazon Key Management Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

UpdateAlias搭配使用 Amazon SDK或 CLI

以下代码示例演示如何使用 UpdateAlias

CLI
Amazon CLI

将别名与其他KMS密钥关联

以下update-alias示例将别名alias/test-key与其他KMS密钥相关联。

--alias-name 参数指定别名。别名值必须以开头alias/。该--target-key-id参数指定要与别名关联的KMS密钥。您无需为别名指定当前KMS密钥。

aws kms update-alias \ --alias-name alias/test-key \ --target-key-id 1234abcd-12ab-34cd-56ef-1234567890ab

此命令不生成任何输出。要查找别名,请使用 list-aliases 命令。

有关更多信息,请参阅中的更新别名 Amazon 密钥管理服务开发人员指南

  • 有关API详细信息,请参阅UpdateAlias中的 Amazon CLI 命令参考

Python
SDK适用于 Python (Boto3)
注意

还有更多相关信息 GitHub。在中查找完整的示例,学习如何设置和运行 Amazon 代码示例存储库

class AliasManager: def __init__(self, kms_client): self.kms_client = kms_client self.created_key = None def update_alias(self, alias, current_key_id): """ Updates an alias by assigning it to another key. :param alias: The alias to reassign. :param current_key_id: The ARN or ID of the key currently associated with the alias. """ new_key_id = input( f"Alias {alias} is currently associated with {current_key_id}. " f"Enter another key ID or ARN that you want to associate with {alias}: " ) if new_key_id != "": try: self.kms_client.update_alias(AliasName=alias, TargetKeyId=new_key_id) except ClientError as err: logger.error( "Couldn't associate alias %s with key %s. Here's why: %s", alias, new_key_id, err.response["Error"]["Message"], ) else: print(f"Alias {alias} is now associated with key {new_key_id}.") else: print("Skipping alias update.")
  • 有关API详细信息,请参阅UpdateAlias中的 Amazon SDK供参考 Python (Boto3) API。

有关完整列表 Amazon SDK开发者指南和代码示例,请参阅使用 Amazon KMS 用一个 Amazon SDK。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。