List of usage examples for com.amazonaws.services.identitymanagement AmazonIdentityManagementClient putRolePolicy
@Override
public PutRolePolicyResult putRolePolicy(PutRolePolicyRequest request)
Adds or updates an inline policy document that is embedded in the specified IAM role.
From source file:awslabs.lab41.SolutionCode.java
License:Open Source License
@Override public String prepMode_CreateRole(AmazonIdentityManagementClient iamClient, String roleName, String policyText, String trustRelationshipText) { String roleArn = null;// w ww .j a v a 2s . c o m // Construct a CreateRoleRequest object using the specified name and "assume role" policy. The policy is the trustRelationshipText parameter. CreateRoleRequest createRoleRequest = new CreateRoleRequest() .withAssumeRolePolicyDocument(trustRelationshipText).withRoleName(roleName); // Submit the request using the createRole method of the iamClient object. // Retrieve and store the role ARN from the request response. roleArn = iamClient.createRole(createRoleRequest).getRole().getArn(); // Construct a PutRolePolicyRequest object using the provided policy for the new role. Use whatever policy name you like. PutRolePolicyRequest putRolePolicyRequest = new PutRolePolicyRequest().withPolicyDocument(policyText) .withPolicyName(roleName + "_policy").withRoleName(roleName); // Submit the request using the putRolePolicy method of the iamClient object. iamClient.putRolePolicy(putRolePolicyRequest); // Return the ARN for the new role. return roleArn; }