AWS AI Services Programming Series - Part7 (Personalize)

   Go back to the Task List

  « 7: Setup Development Environment    9. Clean up »

8: Create Client

In this task, you write python code to call Amazon Personalize Runtime APIs to get movies recommendation for a customer.

  1. 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.

    Personalize

    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']))
    

    `

  2. In the code above, replace {Campaign-Arn} with the personalize campaign ARN you noted in the earlier steps.

  3. 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.

  4. 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.

    Personalize

  5. 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.