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 get detailed information about a customer master key (CMK).

package aws.example.kms; import; import; import; import; import; public class ViewCustomerMasterKey { public static void main(String[] args) { final String USAGE = "To run this example, supply a key id or ARN\n" + "Usage: ViewCustomerMasterKey <key-id>\n" + "Example: ViewCustomerMasterKey 1234abcd-12ab-34cd-56ef-1234567890ab\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String keyId = args[0]; AWSKMS kmsClient = AWSKMSClientBuilder.standard().build(); // Describe a CMK DescribeKeyRequest req = new DescribeKeyRequest().withKeyId(keyId); DescribeKeyResult result = kmsClient.describeKey(req); KeyMetadata metadata = result.getKeyMetadata(); System.out.printf("%-15s %s%n", "KeyId:", keyId); System.out.printf("%-15s %s%n", "Arn:", metadata.getArn()); System.out.printf("%-15s %s%n", "CreationDate:", metadata.getCreationDate()); System.out.printf("%-15s %s%n", "Description:", metadata.getDescription()); System.out.printf("%-15s %s%n", "KeyUsage:", metadata.getKeyUsage()); System.out.printf("%-15s %s%n", "KeyState:", metadata.getKeyState()); System.out.printf("%-15s %s%n", "Origin:", metadata.getOrigin()); System.out.printf("%-15s %s%n", "KeyManager:", metadata.getKeyManager()); } }

Sample Details

Service: kms

Last tested: 2019-04-08

Author: AWS

Type: full-example

On this page: