protected static String createIamRole(String s3Prefix) throws InterruptedException {
        try {
            //set trust policy for the role
            iamClient.createRole(new CreateRoleRequest()
                    .withRoleName(iamRoleName)
                    .withAssumeRolePolicyDocument(getTrustPolicy()));
        } catch (EntityAlreadyExistsException e) {
            LOG.info("IAM role with name " + iamRoleName + " already exists");
        } catch (MalformedPolicyDocumentException policyDocumentException){
			LOG.error(String.format("Please check the trust policy document for malformation: %s",
					IAM_ROLE_TRUST_POLICY_DOCUMENT));
            throw policyDocumentException;
        }

        // Update the role policy with permissions so that principal can access the resources
        // with necessary conditions
        putRolePolicy(s3Prefix);

        String roleARN = iamClient.getRole(new GetRoleRequest().withRoleName(iamRoleName)).getRole().getArn();
        // Sleep for 5 seconds because IAM role creation takes some time to propagate
        Thread.sleep(5000);
        return roleARN;
    }
Method to create the IAM role.

@param s3Prefix the s3Prefix to be specified in role policy (only when KMS key ARN is specified)
@return the role ARN
@throws InterruptedException
src/samples/AmazonKinesisFirehose/AbstractAmazonKinesisFirehoseDelivery.java