AWSSDKAWS KMS key を使用してエイリアスで参照されているものを更新する - AWSSDK コードサンプル

AWSDocAWS SDKGitHub サンプルリポジトリには、さらに多くの SDK サンプルがあります

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWSSDKAWS KMS key を使用してエイリアスで参照されているものを更新する

次のコード例は、エイリアスでの KMS キーを更新する方法を示しています。

Python
SDK for Python (Boto3)
注記

他にもありますGitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

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 の詳細については、「AWSSDK for Python (Boto3) API リファレンス」のを参照してくださいUpdateAlias