文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
DeleteAlias
与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 DeleteAlias
。
- CLI
-
- AWS CLI
-
删除 AWS KMS 别名
以下
delete-alias
示例将删除别名alias/example-alias
。别名名称必须以 alias/ 开头。aws kms delete-alias \ --alias-name
alias/example-alias
此命令不生成任何输出。要查找别名,请使用
list-aliases
命令。有关更多信息,请参阅《AWS 密钥管理服务开发人员指南》中的删除别名。
-
有关 API 的详细信息,请参阅AWS CLI 命令参考DeleteAlias
中的。
-
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /** * Deletes a specific KMS alias asynchronously. * * @param aliasName the name of the alias to be deleted * @return a {@link CompletableFuture} representing the asynchronous operation of deleting the specified alias */ public CompletableFuture<Void> deleteSpecificAliasAsync(String aliasName) { DeleteAliasRequest deleteAliasRequest = DeleteAliasRequest.builder() .aliasName(aliasName) .build(); return getAsyncClient().deleteAlias(deleteAliasRequest) .thenRun(() -> { logger.info("Alias {} has been deleted successfully", aliasName); }) .exceptionally(throwable -> { throw new RuntimeException("Failed to delete alias: " + aliasName, throwable); }); }
-
有关 API 的详细信息,请参阅 AWS SDK for Java 2.x API 参考DeleteAlias中的。
-
- PHP
-
- 适用于 PHP 的 SDK
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /*** * @param string $aliasName * @return void */ public function deleteAlias(string $aliasName) { try { $this->client->deleteAlias([ 'AliasName' => $aliasName, ]); }catch(KmsException $caught){ echo "There was a problem deleting the alias: {$caught->getAwsErrorMessage()}\n"; throw $caught; } }
-
有关 API 的详细信息,请参阅 AWS SDK for PHP API 参考DeleteAlias中的。
-
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 class AliasManager: def __init__(self, kms_client): self.kms_client = kms_client self.created_key = None @classmethod def from_client(cls) -> "AliasManager": """ Creates an AliasManager instance with a default KMS client. :return: An instance of AliasManager initialized with the default KMS client. """ kms_client = boto3.client("kms") return cls(kms_client) def delete_alias(self, alias: str) -> None: """ Deletes an alias. :param alias: The alias to delete. """ try: self.kms_client.delete_alias(AliasName=alias) except ClientError as err: logger.error( "Couldn't delete alias %s. Here's why: %s", alias, err.response["Error"]["Message"], ) raise
-
有关 API 的详细信息,请参阅适用DeleteAlias于 Python 的AWS SDK (Boto3) API 参考。
-
Decrypt
DescribeKey