AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to associate an existing alias with a different CMK.

package aws.example.kms; import; import; import; public class UpdateAlias { public static void main(String[] args) { final String USAGE = "To run this example, supply a key id or ARN and an alias name\n" + "Usage: UpdateAlias <target-key-id> <alias-name>\n" + "Example: UpdateAlias 1234abcd-12ab-34cd-56ef-1234567890ab " + "alias/projectKey1\n"; if (args.length != 2) { System.out.println(USAGE); System.exit(1); } String targetKeyId = args[0]; String aliasName = args[1]; AWSKMS kmsClient = AWSKMSClientBuilder.standard().build(); // Updating an alias UpdateAliasRequest req = new UpdateAliasRequest() .withAliasName(aliasName) .withTargetKeyId(targetKeyId); kmsClient.updateAlias(req); } }

Sample Details

Service: kms

Last tested: 2019-04-09

Author: AWS

Type: full-example

On this page: