Search in sources :

Example 1 with CreateRoleResponse

use of software.amazon.awssdk.services.iam.model.CreateRoleResponse in project aws-doc-sdk-examples by awsdocs.

the class DemoUtils method createPersonalizeRole.

public static String createPersonalizeRole(IamClient iamClient, String roleName) {
    String roleArn = checkRoleExists(iamClient, roleName);
    String minimumPersonalizeAccessPolicyArn;
    try {
        if (roleArn.length() == 0) {
            CreateRoleRequest createRoleRequest = CreateRoleRequest.builder().roleName(roleName).assumeRolePolicyDocument(ASSUME_ROLE_POLICY).description("PersonalizeRole").build();
            CreateRoleResponse response = iamClient.createRole(createRoleRequest);
            roleArn = response.role().arn();
            System.out.println("The ARN of your Amazon Personalize service role is " + roleArn);
        }
        minimumPersonalizeAccessPolicyArn = createPersonalizeIamPolicy(iamClient, "minimumPersonalizeAccessPolicy");
        attachIamPolicyToRole(iamClient, roleName, minimumPersonalizeAccessPolicyArn);
        attachIamPolicyToRole(iamClient, roleName, "arn:aws:iam::aws:policy/AmazonS3FullAccess");
        return roleArn;
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    return roleArn;
}
Also used : CreateRoleRequest(software.amazon.awssdk.services.iam.model.CreateRoleRequest) CreateRoleResponse(software.amazon.awssdk.services.iam.model.CreateRoleResponse) IamException(software.amazon.awssdk.services.iam.model.IamException) NoSuchEntityException(software.amazon.awssdk.services.iam.model.NoSuchEntityException) EntityAlreadyExistsException(software.amazon.awssdk.services.iam.model.EntityAlreadyExistsException) IamException(software.amazon.awssdk.services.iam.model.IamException)

Example 2 with CreateRoleResponse

use of software.amazon.awssdk.services.iam.model.CreateRoleResponse in project flink by apache.

the class AWSServicesTestUtils method createIAMRole.

public static void createIAMRole(IamAsyncClient iam, String roleName) throws ExecutionException, InterruptedException {
    CreateRoleRequest request = CreateRoleRequest.builder().roleName(roleName).build();
    CompletableFuture<CreateRoleResponse> responseFuture = iam.createRole(request);
    responseFuture.get();
}
Also used : CreateRoleRequest(software.amazon.awssdk.services.iam.model.CreateRoleRequest) CreateRoleResponse(software.amazon.awssdk.services.iam.model.CreateRoleResponse)

Aggregations

CreateRoleRequest (software.amazon.awssdk.services.iam.model.CreateRoleRequest)2 CreateRoleResponse (software.amazon.awssdk.services.iam.model.CreateRoleResponse)2 EntityAlreadyExistsException (software.amazon.awssdk.services.iam.model.EntityAlreadyExistsException)1 IamException (software.amazon.awssdk.services.iam.model.IamException)1 NoSuchEntityException (software.amazon.awssdk.services.iam.model.NoSuchEntityException)1