Amazon Web Services Bootcamp
上QQ阅读APP看书,第一时间看更新

Creating a policy version

The following code creates a new policy version for a specific customer-managed policy:

String newPolicyDocument = readFromFile("NewPolicyDocument.json");

updatePolicy(policyARN, newPolicyDocument); ........ public String updatePolicy(
String policyARN,
String policyDocument) {
CreatePolicyVersionRequest createPolicyVersionRequest =
new CreatePolicyVersionRequest()
.withPolicyArn(policyARN)
.withPolicyDocument(policyDocument)
.withSetAsDefault(true);

CreatePolicyVersionResult createPolicyVersionResult =
amazonIdentityManagement.
createPolicyVersion( createPolicyVersionRequest);

return createPolicyVersionResult .getPolicyVersion() .getVersionId();
}

The following is the policy document used to create a policy version NewPolicyDocument.json:

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": "arn:aws:s3:::my-bucket-2"
}]
}