In this task, you write python code to call Amazon Personalize Runtime APIs to get movies recommendation for a customer.
-
In the AWS Cloud9 console, click on the New File option under the File menu to add a new file. Write the following code in the new file and save it as dojoclient.py.
import boto3 client = boto3.client('personalize-runtime') response = client.get_recommendations(campaignArn='{Campaign-Arn}', userId='1', numResults=10) for item in response['itemList']: print ("Item recommended is {0} with score of {1}".format(item['itemId'],item['score']))
`
-
In the code above, replace {Campaign-Arn} with the personalize campaign ARN you noted in the earlier steps.
-
The code is simple. You first create client for personalize runtime. Then you call get_recommendations method to get recommendation for the customer (user id) 1. Finally, you prints all the recommendations and their score from the response.
-
In the console window, execute python dojoclient.py command to run the dojoclient.py code. The code execution finishes in no time and will print the recommendations.
-
This was an example of how you can build client to call Amazon Personalize Runtime APIs. The workshop finishes here. Goto the next task to clean-up the resources so that you don’t incur any cost post the workshop.