-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetUserData.py
28 lines (24 loc) · 927 Bytes
/
getUserData.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
import json
import boto3
from boto3.dynamodb.conditions import Key
from decimal import Decimal
class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Decimal):
return float(obj)
return json.JSONEncoder.default(self, obj)
dynamodb = boto3.resource('dynamodb')
def lambda_handler(event, context):
table = dynamodb.Table('users')
body = table.query(KeyConditionExpression=Key('user-ID').eq(event["queryStringParameters"]['userID']))
items = body['Items']
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token',
'Access-Control-Allow-Credentials': 'true',
'Content-Type': 'application/json'
},
'body': json.dumps(items, cls=DecimalEncoder)
}