Creating recommenders (AWS SDKs) - Amazon Personalize

Creating recommenders (AWS SDKs)

Create a recommender for a domain use case with the following code. Give your recommender a name and provide your Domain dataset group's Amazon Resource Name (ARN). For recipeArn, provide the ARN for your use case. Run this code for each of your domain use cases. The available use cases depend on your domain. For a list of use cases, their ARNs, and their requirements, see Choosing recommender use cases.

SDK for Python (Boto3)
import boto3 personalize = boto3.client('personalize') create_recommender_response = personalize.create_recommender( name = 'recommender name', recipeArn = 'recipe ARN', datasetGroupArn = 'dataset group ARN' ) recommender_arn = create_recommender_response['recommenderArn'] print('Recommender ARN:' + recommender_arn)
SDK for Java 2.x
public static String createRecommender(PersonalizeClient personalizeClient, String name, String datasetGroupArn, String recipeArn) { long maxTime = 0; long waitInMilliseconds = 30 * 1000; // 30 seconds String recommenderStatus = ""; try { CreateRecommenderRequest createRecommenderRequest = CreateRecommenderRequest.builder() .datasetGroupArn(datasetGroupArn) .name(name) .recipeArn(recipeArn) .build(); CreateRecommenderResponse recommenderResponse = personalizeClient.createRecommender(createRecommenderRequest); String recommenderArn = recommenderResponse.recommenderArn(); System.out.println("The recommender ARN is " + recommenderArn); DescribeRecommenderRequest describeRecommenderRequest = DescribeRecommenderRequest.builder() .recommenderArn(recommenderArn) .build(); maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60; while (Instant.now().getEpochSecond() < maxTime) { recommenderStatus = personalizeClient.describeRecommender(describeRecommenderRequest).recommender().status(); System.out.println("Recommender status: " + recommenderStatus); if (recommenderStatus.equals("ACTIVE") || recommenderStatus.equals("CREATE FAILED")) { break; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } return recommenderArn; } catch(PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
SDK for JavaScript v3
// Get service clients module and commands using ES6 syntax. import { CreateRecommenderCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeClient = new PersonalizeClient({ region: "REGION"}); // Set the recommender's parameters. export const createRecommenderParam = { name: 'NAME', /* required */ recipeArn: 'RECIPE_ARN', /* required */ datasetGroupArn: 'DATASET_GROUP_ARN' /* required */ } export const run = async () => { try { const response = await personalizeClient.send(new CreateRecommenderCommand(createRecommenderParam)); console.log("Success", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();