use of software.amazon.awssdk.services.iam.IamClient in project aws-doc-sdk-examples by awsdocs.
the class PersonalizeDemoOnMovieLens20M method main.
public static void main(String[] args) throws Exception {
// Pre-flight step - 1
// Set credentials provider, s3 and personalize clients
// AWSStaticCredentialsProvider cred = getCredentialsProvider();
S3Client s3Client = S3Client.builder().region(region).build();
PersonalizeEventsClient personalizeEventsClient = PersonalizeEventsClient.builder().region(region).build();
PersonalizeClient personalizeClient = PersonalizeClient.builder().region(region).build();
PersonalizeRuntimeClient personalizeRuntimeClient = PersonalizeRuntimeClient.builder().region(region).build();
IamClient iamClient = IamClient.builder().region(Region.AWS_GLOBAL).build();
// Pre-flight step - 2
// Identify your datasets and export them to S3 bucket
DatasetProvider datasetProvider = new MovieLensDatasetProvider();
datasetProvider.exportDatasetToS3(DatasetType.INTERACTIONS, s3Client, S3_BUCKET, true);
// Pre-flight step - 3
// Personalize needs the ability to assume Roles in AWS in order to have the permissions to execute certain tasks, the lines below grant that.
DemoUtils.ensurePersonalizePermissionsOnS3Bucket(s3Client, S3_BUCKET);
// Pre-flight step - 4
// Ensure S3 bucket is accessible by Personalize
String role = PREFIX + "-role";
String roleArn = DemoUtils.createPersonalizeRole(iamClient, role);
// Step 1
// Create dataset group
// Create dataset schemas
// Create datasets
String datasetGroupArn = createSchemaAndDatasets(personalizeClient, datasetProvider, roleArn);
// step 2
// create solution and solution version
final String userPersonalizationRecipeArn = "arn:aws:personalize:::recipe/aws-user-personalization";
final String userPersonalizationSolutionName = PREFIX + "-user-personalization-solution";
final String awsUserPersonalizeSVArn = createSolutionAndSolutionVersion(personalizeClient, datasetGroupArn, userPersonalizationRecipeArn, userPersonalizationSolutionName);
System.out.println("AWS User Personalization solution and solution version created");
final String simsRecipeArn = "arn:aws:personalize:::recipe/aws-sims";
final String simsSolutionName = PREFIX + "-sims-solution";
final String simsSVArn = createSolutionAndSolutionVersion(personalizeClient, datasetGroupArn, simsRecipeArn, simsSolutionName);
System.out.println("SIMS solution and solution version created");
// step 3
// setup campaign
final String userPersonalizationCampaignName = PREFIX + "-user-personalization-campaign";
final CampaignManager userPersonalizationCM = new CampaignManager(personalizeClient, userPersonalizationCampaignName, awsUserPersonalizeSVArn);
final String userPersonalizationCampaignArn = userPersonalizationCM.createAndWaitForResource(true);
System.out.println("AWS User Personalization campaign deployed");
final String simsCampaignName = PREFIX + "-sims-campaign";
final CampaignManager simsCM = new CampaignManager(personalizeClient, simsCampaignName, simsSVArn);
final String simsCampaignArn = simsCM.createAndWaitForResource(true);
System.out.println("SIMS campaign deployed");
// Step 4
// Create event tracker for real time events
// AmazonPersonalizeEvents personalizeEvents = AmazonPersonalizeEventsClientBuilder.standard().withCredentials(cred).build();
final String eventTrackerName = PREFIX + "-event-tracker";
final EventTrackerManager etm = new EventTrackerManager(personalizeClient, eventTrackerName, datasetGroupArn);
final String eventTackerArn = etm.createAndWaitForResource(true);
final String eventTrackingId = etm.getTrackingId(eventTackerArn);
System.out.println("Event tracker created");
// step 5
// create runtime client for demo
runWebDemo(personalizeRuntimeClient, personalizeEventsClient, userPersonalizationCampaignArn, simsCampaignArn, eventTrackingId, datasetProvider);
}
use of software.amazon.awssdk.services.iam.IamClient in project aws-doc-sdk-examples by awsdocs.
the class IAMScenario method main.
public static void main(String[] args) throws InterruptedException {
final String usage = "\n" + "Usage:\n" + " <username> <policyName> <roleName> <roleSessionName> <fileLocation> <bucketName> \n\n" + "Where:\n" + " username - the name of the IAM user to create. \n\n" + " policyName - the name of the policy to create. \n\n" + " roleName - the name of the role to create. \n\n" + " roleSessionName - the name of the session required for the assumeRole operation. \n\n" + " fileLocation - the file location to the JSON required to create the role (see Readme). \n\n" + " bucketName - the name of the Amazon S3 bucket from which objects are read. \n\n";
if (args.length != 6) {
System.out.println(usage);
System.exit(1);
}
String userName = args[0];
String policyName = args[1];
String roleName = args[2];
String roleSessionName = args[3];
String fileLocation = args[4];
String bucketName = args[5];
Region region = Region.AWS_GLOBAL;
IamClient iam = IamClient.builder().region(region).build();
// Create the IAM user.
Boolean createUser = createIAMUser(iam, userName);
if (createUser) {
System.out.println(userName + " was successfully created.");
String polArn = createIAMPolicy(iam, policyName);
System.out.println("The policy " + polArn + " was successfully created.");
String roleArn = createIAMRole(iam, roleName, fileLocation);
System.out.println(roleArn + " was successfully created.");
attachIAMRolePolicy(iam, roleName, polArn);
String name = createServiceLinkedRole(iam);
System.out.println("The Service Linked Role name is " + name);
System.out.println("*** Wait for 1 MIN so the resource is available");
TimeUnit.MINUTES.sleep(1);
assumeGivenRole(roleArn, roleSessionName, bucketName);
System.out.println("*** Get the AWS resources");
getPolicy(iam, polArn);
getRole(iam, roleName);
getSAMLProviders(iam);
getGroups(iam);
getPolicies(iam);
getAttachedRolePolicies(iam, roleName);
getRoles(iam);
System.out.println("*** Getting ready to delete the AWS resources");
deleteServiceLinkedRole(iam, name);
deleteRole(iam, roleName, polArn);
deleteIAMUser(iam, userName);
System.out.println("This IAM Scenario has successfully completed");
} else {
System.out.println(userName + " was not successfully created.");
}
}
use of software.amazon.awssdk.services.iam.IamClient in project aws-doc-sdk-examples by awsdocs.
the class ListUsers method main.
public static void main(String[] args) {
Region region = Region.AWS_GLOBAL;
IamClient iam = IamClient.builder().region(region).build();
listAllUsers(iam);
System.out.println("Done");
iam.close();
}
use of software.amazon.awssdk.services.iam.IamClient in project aws-doc-sdk-examples by awsdocs.
the class AccessKeyLastUsed method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <accessId> \n\n" + "Where:\n" + " accessId - an access key id that you can obtain from the AWS Management Console. \n\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String accessId = args[0];
Region region = Region.AWS_GLOBAL;
IamClient iam = IamClient.builder().region(region).build();
getAccessKeyLastUsed(iam, accessId);
iam.close();
}
use of software.amazon.awssdk.services.iam.IamClient in project aws-doc-sdk-examples by awsdocs.
the class AttachRolePolicy method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <roleName> <policyArn> \n\n" + "Where:\n" + " roleName - a role name that you can obtain from the AWS Management Console. \n\n" + " policyArn - a policy ARN that you can obtain from the AWS Management Console. \n\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String roleName = args[0];
String policyArn = args[1];
// snippet-start:[iam.java2.attach_role_policy.client]
Region region = Region.AWS_GLOBAL;
IamClient iam = IamClient.builder().region(region).build();
// snippet-end:[iam.java2.attach_role_policy.client]
attachIAMRolePolicy(iam, roleName, policyArn);
iam.close();
}
Aggregations