-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (54 loc) · 1.8 KB
/
main.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
# add your get-notes function here
# needs to retrieve the notes from DynamoDB
# boto3 is the aws sdk for python - to interact w/ aws services through this python function
import boto3
import json
import urllib.parse
import urllib.request
from boto3.dynamodb.conditions import Key, Attr
# Create a DynamoDB client
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("lotion-30147402") # create table object
def handler(event: any, context: any):
# # backend authentication check
# access_token = event['headers']['authentication']
# validation_url = f'https://www.googleapis.com/oauth2/v1/userinfo?access_token=${access_token}'
# response = urllib.request.urlopen(validation_url)
# # Parse the response as JSON
# token_info = json.loads(response.read())
# # Check if the token is valid
# if 'error' in token_info:
# return {
# 'statusCode': 401,
# 'body': 'Authentication error'
# }
try:
email = event['queryStringParameters']['email']
response = table.query(KeyConditionExpression=Key('email').eq(email))
if response['Count'] == 0:
response = {
"statusCode": 200,
"body": json.dumps({
'message': "Success",
'data': []
})
}
return response
response = {
"statusCode": 200,
"body": json.dumps({
'message': "Success",
'data': response['Items']
})
}
return response
except Exception as e:
response = {
"statusCode": 404,
"body": json.dumps(
{
'message': "Its not working"
}
)
}
return response