Getting item recommendations (Amazon CLI) - Amazon Personalize
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Getting item recommendations (Amazon CLI)

The following code samples show different variations of how to get item recommendations with the Amazon CLI.

Getting item recommendations

Use the following code to get recommendations from a campaign. To get recommendations from a recommender, replace the campaign-arn parameter with the recommender-arn.

Specify the ID of the user you want to get recommendations for, and the Amazon Resource Name (ARN) of your campaign or recommender. A list of the top 10 recommended items for the user displays. If you use User-Personalization-v2, each recommended item includes a list of reasons for why the item was included in recommendations. For more information, see Recommendation reasons (User-Personalization-v2).

To change the number of recommended items, change the value for numResults. The default is 25 items. The maximum is 500 items. If you used a RELATED_ITEMS recipe to train the solution version backing the campaign, replace the user-id parameter with item-id and specify the item ID.

If you recorded events for a user before they logged in (an anonymous user), you can get recommendations for this user by providing the sessionId from those events as if it is their userId. For more information about recording events for anonymous users, see Recording events for anonymous users.

aws personalize-runtime get-recommendations \ --campaign-arn campaign arn \ --user-id User ID \ --num-results 10

Including item metadata with recommendations

If you enabled metadata in recommendations for your campaign or recommender, you can specify the Items dataset metadata columns to include in the response. For information about enabling metadata for a campaign, see Item metadata in recommendations. For information about enabling metadata for a recommender, see Enabling metadata in recommendations.

The following code sample shows how to specify the metadata columns as part of your request for recommendations.

aws personalize-runtime get-recommendations \ --campaign-arn campaign arn \ --user-id User ID \ --num-results 10 \ --metadata-columns "{\"ITEMS\": ["\"columnNameA"\","\"columnNameB"\"]}"