-
Notifications
You must be signed in to change notification settings - Fork 1
/
LFMatchInfo.py
76 lines (64 loc) · 2.39 KB
/
LFMatchInfo.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# This file is designed for the lambda function to get match information
# in the project CUThen, the final project for COMSE6998_010_2023_3,
# Topics in Computer Science: Cloud Computing and Big Data.
import os
import json
import string
import boto3
from opensearchpy import OpenSearch, RequestsHttpConnection
from requests_aws4auth import AWS4Auth
from botocore.exceptions import ClientError
# question: what is userfeatures returned with userid? Should dynamodb store it?
REGION = 'us-east-1'
HOST = 'search-cuthen-temp-5fyo5fvs7x7t2myle4ztwa7swa.us-east-1.es.amazonaws.com'
INDEX_USER_GROUP = '' # TODO: fill in index
INDEX_GROUP_USER = '' # TODO: fill in index
INDEX_GROUP_LEADER = '' # TODO: fill in index
def get_awsauth(region, service):
cred = boto3.Session().get_credentials()
return AWS4Auth(cred.access_key,
cred.secret_key,
region,
service,
session_token=cred.token)
# query from opensearch instance
def query(term, host, index):
q = {'query': {'multi_match': {'query': term}}}
client = OpenSearch(hosts=[{
'host': host,
'port': 443
}],
http_auth=get_awsauth(REGION, 'es'),
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection)
res = client.search(index=index, body=q)
hits = res['hits']['hits']
return hits
def lambda_handler(event, context):
print(event)
# userID = event['UserId']
# userFeatures = event['UserFeatures']
# groupIDs = query(userID, HOST_USER_GROUP, INDEX_USER_GROUP)
# groups = []
# for gid in groupIDs:
# group = {}
# group['GroupId'] = gid # TODO: confirm opensearch entry format and modify
# gleader = query(gid, HOST_GROUP_LEADER, INDEX_GROUP_LEADER)
# group['GroupLeader'] = gleader # TODO: confirm opensearch entry format and modify
# gmember = query(gid, HOST_GROUP_USER, HOST_GROUP_USER)
# group['GroupMembers'] = gmember # TODO: confirm opensearch entry format and modify
# FOR TESTING ONLY
dummy_response = {
"matchUserProfile": {
"userId": "3",
"userName": "test name",
"userFeatures": []
},
"currentUserGroup": []
}
return {
'statusCode': 200,
"headers": {"Access-Control-Allow-Origin": "*"},
'body': json.dumps(dummy_response)
}