forked from radiantly/GE-Recommendation-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getRecLambda.py
36 lines (25 loc) · 962 Bytes
/
getRecLambda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import boto3
def lambda_handler(event, context):
query = event["queryStringParameters"]
if not query:
return {"statusCode": 400, "body": json.dumps({"message": "No query parameters found"})}
user_id = query["userID"]
if not user_id:
return {"statusCode": 400, "body": json.dumps({"message": "Please specify a user ID"})}
personalize_runtime = boto3.client("personalize-runtime")
campaign_arn = ""
get_recommendations_response = personalize_runtime.get_recommendations(
campaignArn=campaign_arn,
userId=str(user_id),
)
item_list = get_recommendations_response["itemList"]
return {
"statusCode": 200,
"headers": {
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "OPTIONS,POST,GET",
},
"body": json.dumps({"items": item_list}),
}