use of com.amazonaws.services.identitymanagement.model.PutRolePolicyRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElasticBeanstalkSetup method configureInstanceProfileForLogRolingToS3.
/**
* Setup the Role, policy and profile needed for automatic log rolling.
* Note the roleName is the same as the policy name.
*/
private void configureInstanceProfileForLogRolingToS3() {
// Need to grant the EC2 instances access to S3 so our logs can be rotated
String roleName = config.getElasticBeanstalkS3RoleName();
try {
// Try to get the role, if it does not exist then an exception will be thrown.
aimClient.getRole(new GetRoleRequest().withRoleName(roleName));
} catch (NoSuchEntityException e) {
// This means the role does not exist so we must create it.
aimClient.createRole(new CreateRoleRequest().withRoleName(roleName).withAssumeRolePolicyDocument(AssumeRolePolicyDocument));
}
// Set the role policy
aimClient.putRolePolicy(new PutRolePolicyRequest().withRoleName(roleName).withPolicyDocument(ROLE_POLICY).withPolicyName("AdminAccessToS3"));
// Create an instance profile with the same name as the role.
try {
// Check to see if it already exists
aimClient.getInstanceProfile(new GetInstanceProfileRequest().withInstanceProfileName(roleName));
} catch (NoSuchEntityException e) {
// this means it did not exist so we must create it.
aimClient.createInstanceProfile(new CreateInstanceProfileRequest().withInstanceProfileName(roleName));
// Add the policy to the role
aimClient.addRoleToInstanceProfile(new AddRoleToInstanceProfileRequest().withRoleName(roleName).withInstanceProfileName(roleName));
}
}
Aggregations