use of software.amazon.awssdk.services.kms.model.PutKeyPolicyRequest in project aws-doc-sdk-examples by awsdocs.
the class SetKeyPolicy method createPolicy.
// snippet-start:[kms.java2_set_policy.main]
public static void createPolicy(KmsClient kmsClient, String keyId, String policyName) {
String policy = "{" + " \"Version\": \"2012-10-17\"," + " \"Statement\": [{" + " \"Effect\": \"Allow\"," + // Replace the following user ARN with one for a real user.
" \"Principal\": {\"AWS\": \"arn:aws:iam::814548047983:root\"}," + " \"Action\": \"kms:*\"," + " \"Resource\": \"*\"" + " }]" + "}";
try {
PutKeyPolicyRequest keyPolicyRequest = PutKeyPolicyRequest.builder().keyId(keyId).policyName(policyName).policy(policy).build();
kmsClient.putKeyPolicy(keyPolicyRequest);
System.out.println("Done");
} catch (KmsException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations