Use DeleteAlias with an Amazon SDK or CLI - Amazon Key Management Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use DeleteAlias with an Amazon SDK or CLI

The following code examples show how to use DeleteAlias.

CLI
Amazon CLI

To delete an Amazon KMS alias

The following delete-alias example deletes the alias alias/example-alias. The alias name must begin with alias/.

aws kms delete-alias \ --alias-name alias/example-alias

This command produces no output. To find the alias, use the list-aliases command.

For more information, see Deleting an alias in the Amazon Key Management Service Developer Guide.

  • For API details, see DeleteAlias in Amazon CLI Command Reference.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

/** * 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); }); }
  • For API details, see DeleteAlias in Amazon SDK for Java 2.x API Reference.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

class AliasManager: def __init__(self, kms_client): self.kms_client = kms_client self.created_key = None def delete_alias(self): """ Deletes an alias. """ alias = input(f"Enter an alias that you'd like to delete: ") if alias != "": 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"], ) else: print(f"Deleted alias {alias}.") else: print("Skipping alias deletion.")
  • For API details, see DeleteAlias in Amazon SDK for Python (Boto3) API Reference.

For a complete list of Amazon SDK developer guides and code examples, see Using Amazon KMS with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.