Search in sources :

Example 1 with PersonalizeEventsClient

use of software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient 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);
}
Also used : PersonalizeClient(software.amazon.awssdk.services.personalize.PersonalizeClient) PersonalizeRuntimeClient(software.amazon.awssdk.services.personalizeruntime.PersonalizeRuntimeClient) IamClient(software.amazon.awssdk.services.iam.IamClient) CampaignManager(com.amazonaws.personalize.client.resource.CampaignManager) MovieLensDatasetProvider(com.amazonaws.personalize.client.datasets.MovieLensDatasetProvider) S3Client(software.amazon.awssdk.services.s3.S3Client) PersonalizeEventsClient(software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient) EventTrackerManager(com.amazonaws.personalize.client.resource.EventTrackerManager) DatasetProvider(com.amazonaws.personalize.client.datasets.DatasetProvider) MovieLensDatasetProvider(com.amazonaws.personalize.client.datasets.MovieLensDatasetProvider)

Example 2 with PersonalizeEventsClient

use of software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient in project aws-doc-sdk-examples by awsdocs.

the class PutEvents method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    PutEvents <trackingId, userId, sessionId, itemId>\n\n" + "Where:\n" + "    trackingId - The identification number of the dataset group's event tracker." + "The ID is generated by a call to the CreateEventTracker API.\n" + "    userId -The user associated with the event.\n" + "    sessionId - The session ID associated with the user's visit. Your application generates the " + "sessionId when a user first visits your website or uses your application.\n" + "    itemId - The item's identification number.\n\n";
    if (args.length != 4) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String trackingId = args[0];
    String userId = args[1];
    String sessionId = args[2];
    String itemId = args[3];
    // Change to the region where your resources are located
    Region region = Region.US_WEST_2;
    // Build a personalize events client
    PersonalizeEventsClient personalizeEventsClient = PersonalizeEventsClient.builder().region(region).build();
    putEvents(personalizeEventsClient, trackingId, sessionId, userId, itemId);
    personalizeEventsClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) PersonalizeEventsClient(software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient)

Example 3 with PersonalizeEventsClient

use of software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient in project aws-doc-sdk-examples by awsdocs.

the class PutUsers method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    PutUsers <datasetArn, user1Id, user1PropertyName, user1PropertyValue,\n" + "        user2Id, user2PropertyName, user2PropertyValue>\n\n" + "Where:\n" + "    datasetArn - The ARN (Amazon Resource Name) for the user's destination dataset.\n" + "    user1Id - The identification number of the first user.\n" + "    user1propertyName - The metadata field name (in camel case) for the first user.\n" + "    user1propertyValue - The metadata value for the first user.\n" + "    user2Id - The identification number of the second user.\n" + "    user2propertyName - The metadata field name (in camel case) for the second user.\n" + "    user2propertyValue - The metadata value for the second user.\n\n";
    if (args.length != 7) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String datasetArn = args[0];
    String user1Id = args[1];
    String user1PropertyName = args[2];
    String user1PropertyValue = args[3];
    String user2Id = args[4];
    String user2PropertyName = args[5];
    String user2PropertyValue = args[6];
    // Change to the region where your resources are located
    Region region = Region.US_WEST_2;
    // Build a personalize events client
    PersonalizeEventsClient personalizeEventsClient = PersonalizeEventsClient.builder().region(region).build();
    int response = putUsers(personalizeEventsClient, datasetArn, user1Id, user1PropertyName, user1PropertyValue, user2Id, user2PropertyName, user2PropertyValue);
    System.out.println("Response code: " + response);
    personalizeEventsClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) PersonalizeEventsClient(software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient)

Example 4 with PersonalizeEventsClient

use of software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient in project aws-doc-sdk-examples by awsdocs.

the class PutItems method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    PutItems <datasetArn, item1Id, item1PropertyName, item1PropertyValue,\n" + "        item2Id, item2PropertyName, item2PropertyValue>\n\n" + "Where:\n" + "    datasetArn - The ARN (Amazon Resource Name) for the item's destination dataset.\n" + "    item1Id - The identification number of the first item.\n" + "    item1propertyName - The metadata field name (in camel case) for the first item.\n" + "    item1propertyValue - The metadata value for the first item.\n" + "    item2Id - The identification number of the second item.\n" + "    item2propertyName - The metadata field name (in camel case) for the second item.\n" + "    item2propertyValue - The metadata value for the second item.\n\n";
    if (args.length != 7) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String datasetArn = args[0];
    String item1Id = args[1];
    String item1PropertyName = args[2];
    String item1PropertyValue = args[3];
    String item2Id = args[4];
    String item2PropertyName = args[5];
    String item2PropertyValue = args[6];
    // Change to the region where your resources are located
    Region region = Region.US_WEST_2;
    // Build a personalize events client
    PersonalizeEventsClient personalizeEventsClient = PersonalizeEventsClient.builder().region(region).build();
    int response = putItems(personalizeEventsClient, datasetArn, item1Id, item1PropertyName, item1PropertyValue, item2Id, item2PropertyName, item2PropertyValue);
    System.out.println("Response code: " + response);
    personalizeEventsClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) PersonalizeEventsClient(software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient)

Aggregations

PersonalizeEventsClient (software.amazon.awssdk.services.personalizeevents.PersonalizeEventsClient)4 Region (software.amazon.awssdk.regions.Region)3 DatasetProvider (com.amazonaws.personalize.client.datasets.DatasetProvider)1 MovieLensDatasetProvider (com.amazonaws.personalize.client.datasets.MovieLensDatasetProvider)1 CampaignManager (com.amazonaws.personalize.client.resource.CampaignManager)1 EventTrackerManager (com.amazonaws.personalize.client.resource.EventTrackerManager)1 IamClient (software.amazon.awssdk.services.iam.IamClient)1 PersonalizeClient (software.amazon.awssdk.services.personalize.PersonalizeClient)1 PersonalizeRuntimeClient (software.amazon.awssdk.services.personalizeruntime.PersonalizeRuntimeClient)1 S3Client (software.amazon.awssdk.services.s3.S3Client)1