-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_tag.py
31 lines (26 loc) · 919 Bytes
/
search_tag.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
import boto3
import json
def lambda_handler(event, context):
print(event)
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('image_detection')
search_tags = event['usertags']
print(search_tags)
list_url = []
table_metadata = table.scan()
print(table_metadata)
table_data = table_metadata["Items"]
print(table_data)
for entry in table_data:
flag = 0
print(entry)
for tag in entry["tags"]:
print(tag)
for tag_search in search_tags:
if tag == tag_search:
flag += 1
if flag == len(search_tags):
list_url.append(entry["url"])
url_json = {}
url_json["links"] = list(dict.fromkeys(list_url))
return {'statusCode': 200, 'body': json.dumps(url_json), 'headers': {'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': '*'}}